Thank you. I tried adding debug after the roles.
: "{{ ansible_play_hosts_all|
difference(ansible_play_hosts) }}"
But it lists out the wrong instances.
Not sure if it’s coz of the dynamic inventory.
On Tue, Jul 19, 2022 at 12:54 AM Vladimir Botka <[email protected]> wrote:
> On Mon, 18 Jul 2022 22:39:49 -0700 (PDT)
> Vinita Shah <[email protected]> wrote:
>
> > I have a dynamic inventory of hosts. *How do I get a list of failed
> > instances?*
>
> For example,
>
> _failed: "{{ ansible_play_hosts_all|
> difference(ansible_play_hosts) }}"
>
> See
>
> https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#special-variables
>
> Let's test it. Given the inventory
>
> shell> cat hosts
> host1 ok=true
> host2 ok=false
> host3 ok=false
>
> The playbook
>
> - hosts: all
> gather_facts: false
> vars:
> _failed: "{{ ansible_play_hosts_all|
> difference(ansible_play_hosts) }}"
> tasks:
> - assert:
> that: ok|bool
> - debug:
> var: _failed
>
> gives
>
> _failed:
> - host2
> - host3
>
>
> --
> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CALDRKnBG%2BdKn-SHV1fZV2ztdxCC-H_VgRYfgNSvvnn8w7%3DgaWg%40mail.gmail.com.