Hello all, I have a group of switches that users keep asking me to locate mac address for in order to trace down the exact port and edit that port to a new vlan. Rather than logging into each switch and tracking down the switch where the mac resides, I created an ansible a basic ansible playbook to help me with this:
---
- name: Find mac address in sec-switches
hosts: sec-switch
gather_facts: false
connection: local
vars_prompt:
- name: mac
prompt: What is the mac address?
private: no
tasks:
-
name: debugging
ansible.builtin.debug:
msg: 'Searching for {{ mac }}'
-
name: "search"
register: output
ios_command:
commands:
- "show mac address-table | include {{ mac }}"
-
debug: var=output.stdout_lines
When ran, my debug gives me:
(snippet)
}
ok: [10.1.1.32] => {
"output.stdout_lines": [
[
"24 0050.f967.5cb7 DYNAMIC Gi1/0/48"
]
]
}
ok: [10.1.1.33] => {
"output.stdout_lines": [
[
"24 0050.f967.5cb7 DYNAMIC Gi1/0/48"
]
]
}
ok: [10.1.1.30] => {
"output.stdout_lines": [
[
"4 0050.f967.5cb7 DYNAMIC Gi1/1/1",
" 24 0050.f967.5cb7 DYNAMIC Gi1/1/1"
]
]
}
I'd like to filter the output and for each switch run the sh interfaces description | inc { using the returned interfaces}. This way I can rule out uplinks.
IE: On switch 10.1.1.33 I ran: sh interfaces description | inc Gi1/0/48
and it returned: Gi1/0/48 up up UPLINK
That lets me know I don't need to worry about that switch as its an uplink.
I tried seeing if my returned output was a dictionary, but the playbook complained when I added {{ myvar | type_debug }} under my debug statement as: {{ output | type_debug }}
Thanks in advance.