Track list of failed/success tasks into a file.

Dear All,

I have static inventory which contains more then 100 hosts/cluster.

While running ansible playbook, there is a chance any of host/cluster got failed to execute the task due to some reason.

We have to capture those this details to one file(CSV) along with other required data. Could anyone please suggest if we have way to track? Thank you

We are using static inventory.

Example we need to track:

Number of hosts/clusters: 110
Task success: 107
Failed:3

Just to add,

Playbook will execute to static inventory host/cluster list over the loop.

See https://ansible-runner.readthedocs.io/en/stable/

The artifacts will keep data to create the report.

Hi Vladimir Botka,

Thanks for your response. I will go through doc ansible-runner.

If you mistakenly believe using ansible-runner is too much work, then you can instead do even more work to put your tasks in blocks with rescue and always sections to record the data which you can later collate. See https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_blocks.html#handling-errors-with-blocks for details.

If you can live with less fine-grained information - i.e. not down to the task level - then familiarize yourself with RETRY_FILES_ENABLED and RETRY_FILES_SAVE_PATH. See ansible-config list for details on those. These tell Ansible to list the hosts which failed a run in the designated file.

Another possibility that fits sort of in-between the first two is to insert a run_once: true task at select points in your playbook to compare the ansible_play_hosts_all and ansible_play_hosts lists to see how they differ. The difference will be the hosts which have failed at that point. The effectiveness of this method depends on the strategy your plays employ. In other words, all hosts’ task executions have to be in-sync at the time this run_once task runs. (I have not experimented with this. Nor with the other suggestions either.)

Thank you Todd.

Many options you have provided. I will go through it and see what works for my requirement.