Hello,
I try to figure out, how I can find the failed hosts in rescue.
My idea was to use:
- name: add failed hosts to the exclude list
add_host:
name: “{{ item }}”
groups: failed_hosts_in_block
when: hostvars:[item][‘ansible_failed_result’][‘failed’] == true
with_items: “{{ stored_ansible_hosts }}”
stored_ansible_hosts contains all ansible_play_hosts right at the beginning of the play.
The above code does not work, because when does not like the hostvar variable somehow “conditional check errors”. I tried a lot of possible combinations
hostvars:[item]ansible_failed_result’.failed
hostvars:[item][‘ansible_failed_result’].failed
hostvars:[item][‘ansible_failed_result’][‘failed’]
.
.
even:
- debug:
var: hostvars[hostname].ansible_failed_result.failed
or
- debug:
msg: “{{ hostvars[hostname].ansible_failed_result.failed }}”
gives the result “true”
For me, it is only important to find out, which host failed. There are a lot of tasks in the block statement and it makes no sense to write error handling for each single task, register the return code and take action on this one. Also adding these hostnames to a list failed (thought that failed hosts could not be added to a host group…)
I hope you can help!
Regards