Today my task was to find out if a given switch is a member of a stack or not.
Starting with manual testing, in order to find out if it’s a stack, i used the command: show switch detail. If there is more than one member, it’s a stack.
In Ansible, I registered the show switch detail command and then parsed it with Genie using the clay584 Ansible plugin.
Finally, I used an assert task to find out how many elements (IDs) are under the stack.
Easy peasy japanese.
(...)
- name: show virtual chassis detail
block:
- name: run show switch detail
ios_command:
commands: show switch detail
register: show_sw_detail
- name: set fact show switch detail
set_fact:
switch_detail_data: "{{show_sw_detail['stdout'][0] | clay584.genie.parse_genie(command='show switch detail', os='ios') }}"
- name: assert that there is more than one member in the stack
assert:
that:
(switch_detail_data["switch"]["stack"]|length > 1)