Need to filter with_items values based on specific string

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 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

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

It worked. Thanks, much !!