Maybe use the value of "ping_res.rc".  It's the return code of the command;
so it would be "0" for success.

Eg:

{{ (ping_res.rc|int == 0) | ternary('UP', 'DOWN') }}

--Steve

On Thu, Apr 18, 2019 at 12:15 AM Vandana Thakur <[email protected]>
wrote:

> 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.:)
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CALJDb0mMwEGMXR3LP1vfOPjumBL9xkdYU9Hy-jRZNq_v%3DvhFMw%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CALJDb0mMwEGMXR3LP1vfOPjumBL9xkdYU9Hy-jRZNq_v%3DvhFMw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFbiokcDVo4uFVoq%3DLf%2B%3D8E1r7PhFxCtkSdVvtE8kjA04mTgyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to