Hello,
I'm fairly new to Ansible and trying to do something very simple. I want to collect a piece of information (version number) from a number a network devices and generate a simple report.
- name: Get Data from devices
gather_facts: False
hosts: all
connection: local
roles:
- Juniper.junos
tasks:
- name: Netconf test
wait_for: host={{ inventory_hostname }} port=830 timeout=5
# Do a quick test to gather facts
- name: Getting Facts
junos_get_facts: host={{ inventory_hostname }} logfile=tmp.log user=me passwd=passwd123
register: data
- name: Save version data to jinja2 template
template: src=junos_version_report.j2 dest=./ver_report.txt
Here is the j2 file:
Device Serial Number Version
--------- ------------- ------------
{% for i in play_hosts %}
{{ i }} {{ data.facts.serialnumber }}
{% endfor %}
The problem is when the report is written to the file, the information in the "data" variable is only from the last device that set it... As you can see, the Serial number is reported as being identical for each device ( which it is not...)
Device Serial Number Version
--------- ------------- ------------
dev1 77633B97ACF0
dev2 77633B97ACF0
dev3 77633B97ACF0
I've seen an example like this with the hostvars variable but how do I define my own variable to be an array like hostvars so I can then reference each object in the array. For example:
{{ data[i].facts.serialnumber }}
Or open to other ideas?
Thanks
Al