Hello,
I need to obtain information on many Cisco Catalyst switches, including, hostname, serial number, and model # and export it to a csv.
I can do that with the playbook I have below.
The problem I am having is that many of my switches are stacks of several physical switches and Ansible is only getting the serial number of one of the switches in the stack.
Does anyone know how I can make Ansible get the serial numbers from all switches in a stack?
- name: Gather information from Cisco devices
hosts: all
gather_facts: no
tasks:- name: Gather Cisco device information
cisco.ios.ios_facts:
register: device_info - name: Create a list of the required details
set_fact:
device_details:- hostname: “{{ device_info.ansible_facts.hostname }}”
model: “{{ device_info.ansible_facts.model }}”
serial_number: “{{ device_info.ansible_facts.serial_number }}”
- hostname: “{{ device_info.ansible_facts.hostname }}”
- name: Export to CSV file
copy:
content: |
hostname,model,serial_number
{% for device in device_details %}
{{ device.hostname }},{{ device.model }},{{ device.serial_number }}
{% endfor %}
dest: “/home/admin/virtual02/cisco_device_info.csv”
mode: ‘0644’
- name: Gather Cisco device information