attempts key

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.

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.

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.