Track list of failed/success tasks into a file.

25 views
Skip to first unread message

Aharonu

unread,
Mar 9, 2023, 7:06:34 PM3/9/23
to ansible...@googlegroups.com
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

Aharonu

unread,
Mar 9, 2023, 7:11:31 PM3/9/23
to ansible...@googlegroups.com
Just to add,

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

Vladimir Botka

unread,
Mar 9, 2023, 7:16:50 PM3/9/23
to Aharonu, ansible...@googlegroups.com
See https://ansible-runner.readthedocs.io/en/stable/

The artifacts will keep data to create the report.


--
Vladimir Botka

Aharonu

unread,
Mar 9, 2023, 7:31:28 PM3/9/23
to Vladimir Botka, ansible...@googlegroups.com
Hi Vladimir Botka,

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

Todd Lewis

unread,
Mar 10, 2023, 9:44:17 AM3/10/23
to Ansible Project
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.)

Aharonu

unread,
Mar 10, 2023, 12:29:54 PM3/10/23
to ansible...@googlegroups.com, Todd Lewis
Thank you Todd.

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


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/351b1582-8aa9-44ca-a654-33f8f3edaa45n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages