Hello Everyone,
Greetings!
I am working to get failed hosts from ‘rescue’ section into a CSV file.
When i run task for 'inventory_hostname’ from ‘rescue’ section:
rescue:
- name: inventory_host name list debug
debug:
msg: “{{ inventory_hostname }}”
Output:TASK [inventory_host name list debug] *******************************************************************************************************************************************************************************************************
ok: [bogus1] => {}MSG:
bogus1
ok: [bogus2] => {}MSG:
bogus2
when i tried to append data to a list.
- set_fact:
failed_list: “{{ failed_list + [ansible_host] }}”- name: failed_list debug
debug: var=failed_list
Output:
TASK [set_fact] *****************************************************************************************************************************************************************************************************************************
ok: [bogus1]
ok: [bogus2]
TASK [failed_list debug] ********************************************************************************************************************************************************************************************************************
ok: [bogus1] => {
“failed_list”: [
“bogus1”
]
}
ok: [bogus2] => {
“failed_list”: [
“bogus2”
]
}
Here bogus1, bogus2 host names are failed in ‘resce’ section.
We have multiple hosts in our environment. While running playbook we have to capture failed hostname into a file as mentioned below:
failed_hosts.csv:
number of failed hots: 2
hostname:
bogus1
bogus2
Thank you for your help.