Ansible writing output from multiple task to a single file


In Ansible, I have written an Yaml playbook that takes list of host name and the executes command for each host. I have registered a variable for these task and at the end of executing a task I append output of each command to a single file.
But every time I try to append to my output file, only the last record is getting persisted.

I even tried to append using lineinfile using insertafter parameter yet was not successful.
Anything that I am missing?


You can try something like this:

I have used serial: 1 as I am not sure if lineinfile tasks running in parallel will garble the output file.

Leave a Reply