The use case is to run a specific task once over all hosts only when at least one host failed the previous task.
It could be something like:
-
name: How to list a subelement from hostvars for all ansible_play_hosts
gather_facts: True
hosts: all
strategy: debug
tasks: -
name: Run first task
include_tasks: “task.yml”
register: return_task
ignore_errors: yes -
name: Run second task when first task has failed on at least one playing host
debug:
msg: “first task has failed on at least one of: {{ ansible_play_hosts }}”
when: ansible_play_hosts | map(‘extract’, hostvars, ‘return_task.failed’) | list is any
The conditional makes the last task fail with:
‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘return_task.failed’
Any suggestion to correct the conditional?