Vladimir, this is very good, and very appreciated. Your playbook looks for 
hosts that are pingable, and marks them as not unreachable.  But, my goal 
is to see if hosts are Ansible-pingable (not ICMP-pingable; I believe 
there's a difference) or not, then take *all* of the output, and create a 
report from it. Thus, i end up with a report of hosts that are either 
Ansible-pingable or not.

On Tuesday, November 7, 2023 at 2:15:30 PM UTC-5 Vladimir Botka wrote:

> Sure, here is the gist
> https://gist.github.com/vbotka/10c57962976dd1e2dd3e9411d3745c75
>
> (Is it possible to reasonably format a code in Google Groups?)
> On Tuesday, November 7, 2023 at 6:55:50 PM UTC+1 dbs34 wrote:
>
>> would you mind sharing the whole, newly updated playbook?  thank you!
>>
>> On Monday, November 6, 2023 at 2:58:31 PM UTC-5 Vladimir Botka wrote:
>>
>>> On Fri, 3 Nov 2023 08:40:19 -0700 (PDT) 
>>> Dimitri Yioulos <dimitri....@gmail.com> wrote: 
>>>
>>> > --- PING REPORT --- 
>>> > {% for pr in ping_result.results %} 
>>> > {{ pr.stdout_lines | first }} 
>>> > {{ pr.stdout_lines | last }} 
>>> > 
>>> > {% endfor %} 
>>> > run_once: true 
>>> > delegate_to: localhost 
>>> > 
>>> > That works fine. However, I want to use ansible.builtin.ping ... 
>>>
>>>
>>> Ignore unreachable hosts in a block 
>>>
>>> - block: 
>>> - ping: 
>>> register: out 
>>> - set_fact: 
>>> unr: "{{ out.unreachable|d(false) }}" 
>>> ignore_unreachable: true 
>>>
>>> and declare the dictionary 
>>>
>>> h_unr: "{{ dict(ansible_play_hosts_all| 
>>> zip(ansible_play_hosts_all| 
>>> map('extract', hostvars, 'unr'))) }}" 
>>>
>>> For example, the below play 
>>>
>>> - hosts: test_01,test_05,test_06,test_07 
>>> gather_facts: false 
>>>
>>> vars: 
>>>
>>> h_unr: "{{ dict(ansible_play_hosts_all| 
>>> zip(ansible_play_hosts_all| 
>>> map('extract', hostvars, 'unr'))) }}" 
>>>
>>> tasks: 
>>>
>>> - block: 
>>> - ping: 
>>> register: out 
>>> - set_fact: 
>>> unr: "{{ out.unreachable|d(false) }}" 
>>> ignore_unreachable: true 
>>>
>>> - debug: 
>>> var: h_unr 
>>> run_once: true 
>>> delegate_to: localhost 
>>>
>>> gives (abridged) 
>>>
>>> ok: [test_01 -> localhost] => 
>>> h_unr: 
>>> test_01: false 
>>> test_05: true 
>>> test_06: true 
>>> test_07: true 
>>>
>>> -- 
>>> Vladimir Botka 
>>>
>>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/47bbdd8e-7b5f-4dfc-ac60-375a532a9adbn%40googlegroups.com.

Reply via email to