Hello Team,
I have created a csv for gathered facts of linux and windows targets.
Now i am trying to add a column with Ping module status and result code if it fails.
I wrote this play in the role- this is for linux targets :
---
- ping:
register: result
- debug: var=hostvars[inventory_hostname].result
- setup:
delegate_facts: True
- lineinfile:
create: yes
dest: /{{csv_log}}/setup.csv
line: "Ping,Hostname,CPU_Architecture,OS,OS_VERSION,Customer_name,Location,Project"
state: present
delegate_to: localhost
delegate_facts: True
- lineinfile:
create: yes
regexp: "NONEXISTENTLINE"
dest: /{{csv_log}}/setup.csv
line: "{{ping_res.stdout_lines}},{{hostvars[inventory_hostname]['ansible_default_ipv4']['address']}},{{ inventory_hostname }},{{ ansible_architecture }},{{ ansible_distribution }},{{ ansible_distribution_version }}"
state: present
delegate_to: localhost
delegate_facts: True
BUT the issue is , it gives all the output like :
[root@vuhplabspawx001 tasks]# cat /tmp/setup.csv
Ping,Hostname,CPU_Architecture,OS,OS_VERSION,Customer_name,Location,Project
[u'PING vuhplabspawx001 (172.20.24.188) 56(84) bytes of data.', u'64 bytes from vuhplabspawx001 (172.20.24.188): icmp_seq=1 ttl=64 time=0.039 ms', u'', u'--- vuhplabspawx001 ping statistics ---', u'1 packets transmitted, 1 received, 0% packet loss, time 0ms', u'rtt min/avg/max/mdev = 0.039/0.039/0.039/0.000 ms'],
172.20.24.188,vuhplabspawx001,x86_64,CentOS,7.2.1511
[root@vuhplabspawx001 tasks]#
How can i sort this description to only status and result code if it fails.
Thanks in advance.:)