I just did something very similar:
- name: Check Nodes
hosts: all
gather_facts: false
tasks:
- name: ping hosts
ping:
ignore_errors: True
ignore_unreachable: True
register: ping_results
- hosts: localhost
gather_facts: false
tasks:
- name: Add failed hosts to failed_group
add_host:
hostname: "{{ item }}"
groups: unreachable
when: hostvars[item]['ping_results'] is unreachable
loop: '{{groups["all"]}}'
- name: just for show, but here you can do any actions like
'bootstraping' the machines, removing from inventory, etc
debug:
msg: "{{ groups['unreachable'] }}"
--
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/CACVha7fhM-iZFQTXj%3D9fBVkYAcXSc9KR30idzr2eO0WcabF-BA%40mail.gmail.com.