attempts key

31 views
Skip to first unread message

jepper

unread,
Dec 29, 2015, 9:59:26 AM12/29/15
to Ansible Project
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 mentions said attempts key.

Matt Martz

unread,
Dec 29, 2015, 10:14:29 AM12/29/15
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/18c909f5-8613-4210-8677-61fac50e85c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

jepper

unread,
Dec 29, 2015, 12:23:06 PM12/29/15
to Ansible Project
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. 
Reply all
Reply to author
Forward
0 new messages