# Ansible to get info from all Cisco switches in a stack

**URL:** <https://forum.ansible.com/t/ansible-to-get-info-from-all-cisco-switches-in-a-stack/40160>\
**Category:** Get Help\
**Created:** [February 10, 2025, 7:23pm UTC](https://forum.ansible.com/t/ansible-to-get-info-from-all-cisco-switches-in-a-stack/40160 "2025-02-10T19:23:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjensen](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@mjensen](https://forum.ansible.com/u/mjensen)\
**Post date:** [February 10, 2025, 7:23pm UTC](https://forum.ansible.com/t/ansible-to-get-info-from-all-cisco-switches-in-a-stack/40160/1 "2025-02-10T19:23:51Z")

</div>

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 }}”

  - 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’
