I am trying to create a csv file with the following Ansible playbook:
- name: Find Fex Enclosure
hosts: MAQ
gather_facts: no
connection: local
tasks:
- name: GET VENDOR & OS OF THE EQUIPEMENT
snmp_device_version:
host={{ inventory_hostname }}
version=3
integrity=xxxx
level=authPriv
privacy=xxxx
username=xxxxxx
authkey=xxxxxxx
privkey=xxxxxxx
- name: SHOW FEX
ntc_show_command:
connection=netmiko_ssh
platform={{ ansible_device_vendor }}_{{ ansible_device_os }}
command='show fex'
host={{ inventory_hostname }}
username={{ ansible_user }}
password={{ ansible_pass }}
template_dir=/usr/share/ansible/plugins/modules/ntc-ansible/ntc-templates/templates/
register: fex_list
- name: SHOW FEX By ID
ntc_show_command:
connection=netmiko_ssh
platform={{ ansible_device_vendor }}_{{ ansible_device_os }}
command='show fex {{ item.number }}'
host={{ inventory_hostname }}
username={{ ansible_user }}
password={{ ansible_pass }}
template_dir=/usr/share/ansible/plugins/modules/ntc-ansible/ntc-templates/templates/
register: fex_conf
with_items: "{{ fex_list.response }}"
- name: create File.csv with content from fex_conf
copy:
content: "{{ inventory_hostname }};{{ item.1.fex }};{{ item.1.description }};{{ item.1.extender_serial }};{{ item.1.extender_model }};{{ item.1.enclosure }};{{ item.1.enclosure_serial }};{{ item.1.fabric_port }}\n"
dest: out/file.csv
loop: "{{ fex_conf.results | subelements('response') }}"
when: item.1.enclosure !=""
The problem is that it only writes the last iteration to the file.csv
this is what I got:
cat out/file.csv 999.999.999.8;114;MEF114-999-SS1999;FOC199999;N2K-B22HP-P;SS1-999-12;CZ3....;Eth1/13
I am expecting at least 6 lines. Do not know what to do, when I do a debug I get the 6 lines as msg.SO the loop is working.
I have also tried the Template way, but stuck in doing a loop with subelements on Jinja2. I do not know how to do it.
If any one could point me in the right direcction, i will appreciated.
Many Thnaks