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



-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/15deec67-b01e-4b92-9261-ae4614d5d200%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to