# attempts key

**URL:** <https://forum.ansible.com/t/attempts-key/20094>\
**Category:** Ansible Project\
**Created:** [December 29, 2015, 2:59pm UTC](https://forum.ansible.com/t/attempts-key/20094 "2015-12-29T14:59:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [December 29, 2015, 2:59pm UTC](https://forum.ansible.com/t/attempts-key/20094/1 "2015-12-29T14:59:26Z")

</div>

Hi, please can someone explain to me how to use “attempts” with retries? E.g. here’s what I want to do:

- name: health check - wait for endpoints to become available  
action: shell curl “{{ item.endpoint }}/health”  
failed\_when: attempts \> 5

retries: 6  
delay: 10

For reference: [http://docs.ansible.com/ansible/playbooks\_loops.html](http://docs.ansible.com/ansible/playbooks_loops.html) mentions said attempts key.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 29, 2015, 3:13pm UTC](https://forum.ansible.com/t/attempts-key/20094/2 "2015-12-29T15:13:44Z")

</div>

You need to `register` a variable on the task as well. Such as:

- name: health check - wait for endpoints to become available  
shell: curl “{{ item.endpoint }}/health”  
register: endpoint\_health  
failed\_when: endpoint\_health.attempts \> 5

retries: 6  
delay: 10

Additionally, I notice that you are using `item.endpoint`, which indicates that you are using something such as `with_items`, but you did not include this on your task.

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [December 29, 2015, 5:23pm UTC](https://forum.ansible.com/t/attempts-key/20094/3 "2015-12-29T17:23:06Z")

</div>

I got it working, thanks for the suggestion. Here’s what I ended up doing:

- name: wait for endpoints to become available  
action: shell curl “{{ item.endpoint }}/health”  
when: “item.endpoint is defined”  
with\_items: “{{ deploy\_list }}”  
register: log\_output  
until: log\_output.stdout.find(“UP”) \> -1  
changed\_when: false  
failed\_when: “log\_output.attempts \> {{ deploy\_health\_check\_retries - 1 }}”  
retries: “{{ deploy\_health\_check\_retries }}”  
delay: “{{ deploy\_health\_check\_delay }}”

The next thing that would be nice would be to fork this, as many times as I have URLs to check.
