# How to loop over result and retry in the same task?

**URL:** <https://forum.ansible.com/t/how-to-loop-over-result-and-retry-in-the-same-task/26527>\
**Category:** Ansible Project\
**Created:** [January 22, 2018, 3:03am UTC](https://forum.ansible.com/t/how-to-loop-over-result-and-retry-in-the-same-task/26527 "2018-01-22T03:03:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Chong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/eric_chong/32/9436_2.png) [@Eric\_Chong](https://forum.ansible.com/u/Eric_Chong)\
**Post date:** [January 22, 2018, 3:03am UTC](https://forum.ansible.com/t/how-to-loop-over-result-and-retry-in-the-same-task/26527/1 "2018-01-22T03:03:35Z")

</div>

For example, if I want a task to pull ec2\_instance\_facts until any instance is in running state, and retry if none is running.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 6, 2018, 5:30pm UTC](https://forum.ansible.com/t/how-to-loop-over-result-and-retry-in-the-same-task/26527/2 "2018-02-06T17:30:56Z")

</div>

you cannot loop over the results of your task that is generating those  
results, you CAN loop over the results of one task in a second task.

---

<div class="post-metadata">

**Author:** ![Eric\_Chong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/eric_chong/32/9436_2.png) [@Eric\_Chong](https://forum.ansible.com/u/Eric_Chong)\
**Post date:** [February 8, 2018, 2:35pm UTC](https://forum.ansible.com/t/how-to-loop-over-result-and-retry-in-the-same-task/26527/3 "2018-02-08T14:35:50Z")

</div>

But I want to retry the first task until expected result. I don’t see a way for Ansible to retry a bock of tasks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 8, 2018, 7:50pm UTC](https://forum.ansible.com/t/how-to-loop-over-result-and-retry-in-the-same-task/26527/4 "2018-02-08T19:50:39Z")

</div>

you CAN retry the first task, use until condition, i dont see a block  
of tasks ...
