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/20220719085403.6905e2a2%40gmail.com.

Attachment: pgpb06LRuZ4m0.pgp
Description: OpenPGP digital signature

Reply via email to