# Getting changed/failed hosts list from a previous task

**URL:** <https://forum.ansible.com/t/getting-changed-failed-hosts-list-from-a-previous-task/35045>\
**Category:** Ansible Project\
**Created:** [April 24, 2021, 10:37am UTC](https://forum.ansible.com/t/getting-changed-failed-hosts-list-from-a-previous-task/35045 "2021-04-24T10:37:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumith\_nair](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sumith\_nair](https://forum.ansible.com/u/sumith_nair)\
**Post date:** [April 24, 2021, 10:37am UTC](https://forum.ansible.com/t/getting-changed-failed-hosts-list-from-a-previous-task/35045/1 "2021-04-24T10:37:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sumith\_nair](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@sumith\_nair](https://forum.ansible.com/u/sumith_nair)\
**Post date:** [April 25, 2021, 4:28am UTC](https://forum.ansible.com/t/getting-changed-failed-hosts-list-from-a-previous-task/35045/2 "2021-04-25T04:28:19Z")

</div>

Any sort of lead would be appreciated
