Logout Automation in Cisco ACI

19 Views Asked by At

I need help automating the Logout of users from the CISCO ACI APIC, this is because after carrying out my automation tasks in Ansible or Python (REST API) the section becomes active.

apic1# show aaa sessions

Username | Type | Host | Login Time


admin | local | 10.10.10.1 | 2024-02-28T02:14:45.054+00:00

admin | local | 10.10.10.1 |2024-02-28T02:14:.054+00:00

admin | local | 10.10.10.2 |2024-02-28T02:15:.04+00:0

So I tried in my laboratory to create a python script that logs out all users, but it doesn't seem to work.

import request



login_url = f"https://{apic_ip}/api/aaaLogin.json"
login_payload = {
    "aaaUser": {
        "attributes": {
            "name": username,
            "pwd": password
        }
    }
}
login_response = requests.post(login_url, json=login_payload, verify=False)
auth_token = login_response.json()['imdata'][0]['aaaLogin']['attributes']['token']

# Desconectar usuários
logout_url = f"https://{apic_ip}/api/aaaLogout.json"
logout_headers = {
    'Cookie': f"APIC-Cookie={auth_token}"
}
logout_response = requests.post(logout_url, headers=logout_headers, verify=False)

I was successful in doing this in Postman, but it logs out only from the section that ran the REST API:

URI:https://172.16.151.152/api/aaaLogout.json
Body:{"aaaUser": {"attributes": {"name": "admin"}}}
Result:"totalCount": "0", "imdata": []

So I ask for help to try other alternatives, which could be a way through Ansible or Python

0

There are 0 best solutions below