After executing an ansible playbook, I need the node names that were not reached. I thought about using AnsibleRunner
for running the ansible-playbook and I know of the special variables ansible_play_hosts
and ansible_play_hosts_all
which you can diff to get the unreachable nodes. But those special variables only exist in the context of ansible.
So how do I get the unreachable nodes from AnsibleRunner
(or a similar utility), without parsing ansible's output.
On Runner Objects
Currently I am creating a runner object and evaluating its variables after execution. I see that in the events I can theoretically look for unreachable nodes, but that seems to be quite sketchy.
One might also be able to write an event handler that specifically catches those events that indicate that a node is unreachable that handles those cases differently.
I also wrote a small fact registration that registers which nodes are unreachable which will be executed as a last task, but I couldn't access it yet:
- set_fact:
unreachable: "{{ ansible_play_hosts_all|difference(ansible_play_hosts) }}"
On ansible API
The ansible API has in its example a dictionary called host_unreachable
. While that sounds very promising I have two issues with it: I) I couldn't run the example II) The API will not be downwards compatible and therefore shouldn't be used externally.