Getting changed/failed hosts list from a previous task

All,

As part of my playbook, i’d like to know the list of hosts where a certain task executed and changed something or got failed. Since i need to use those hosts in the very next task in same playbook for some other action.

Example: If i’ve got 10 hosts for a playbook, and below task changed/failed on 5 out of the 10 and skipped other 5, i need to gather those affected 5 hosts into a variable maybe, then use that in next task.

  • name: update file count

shell: “echo 2 > /home/ec2-user/abcd.txt”

when:

  • count.stdout == “1”

register: update1

Thank you.

Any sort of lead would be appreciated