On 11/25/19 2:42 PM, Pandu jh wrote:
> 
> I need to reject "none" value item in ping test task. It has to take only 
> "non- none" values from the with_items in the
> task.
>  Please help me to fix this.
> 
>       - set_fact:
>           linux_ip: "{{ item.stdout_lines[0] }}"
>           unix_ip: "{{ item.stdout_lines[1] | default('none') }}"
>         loop: "{{ ip_address_api.results }}"
> 
>       - debug:  var=unix_ip
>       - debug:  var=linux_ip
> 
> 
>       - name: Ping Test
>         win_shell:  |
>             if (Test-Connection {{  item  }} -Quiet -Count 2) {
>             write-host "Ping - Successful"
>             }
>             else {
>             Write-Host "Ping - Failed"
>             }
>         register: ping_check
>         ignore_errors:  yes
>         with_items:
>           - "{{ unix_ip  }}"
>           - "{{ linux_ip }}"
>       - debug: var=ping_check

I can imagine various solutions to the problem, but

          when: "item != 'none'"

should do the trick.

Regards
         Racke

> 
> I tired with reject filter but it did not work.
> 
>       - name: Ping Test
>         win_shell:  |
>             if (Test-Connection {{  item  }} -Quiet -Count 2) {
>             write-host "Ping - Successful"
>             }
>             else {
>             Write-Host "Ping - Failed"
>             }
>         register: ping_check
>         ignore_errors:  yes
>         with_items:
>           - "{{  unix_ip | reject('match','none) | list  }}"
>           - "{{ linux_ip   }}"
>       - debug: var=ping_check
> 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1f050f15-5ff1-456e-8726-16a316578dd4%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1f050f15-5ff1-456e-8726-16a316578dd4%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/512aa9a2-e526-10dc-9445-d4b4e5496142%40linuxia.de.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to