Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ansible wait_for http
- name: wait_for http
command: "curl --silent {{ url }}"
register: result
until: result.stdout.find("200 OK") != -1
retries: 60
delay: 1
changed_when: false
@realjktu

This comment has been minimized.

Copy link

commented May 21, 2018

As far is this gist is on top of Google search now :) the best solution is to use uri ansible module like below.

  • name: "wait for ABC to come up"
    uri:
    url: "http://127.0.0.1:8080/ABC"
    status_code: 200
    register: result
    until: result.status == 200
    retries: 60
    delay: 1
@vlakas

This comment has been minimized.

Copy link

commented Jun 15, 2018

@realjiktu nice workaround. But... version with curl is more reliable. uri depends on httplib2 python library which must be installed on remote host.

failed: [boomslang] => {"failed": true}
msg: httplib2 is not installed

FATAL: all hosts have already failed -- aborting
@geerlingguy

This comment has been minimized.

Copy link

commented Sep 28, 2018

The above comment, formatted a little more nicely:

- name: "wait for ABC to come up"
  uri:
    url: "http://127.0.0.1:8080/ABC"
    status_code: 200
  register: result
  until: result.status == 200
  retries: 60
  delay: 1

This will try the URL every second for up to 60 seconds before failing.

@j-chimienti

This comment has been minimized.

Copy link

commented Jan 3, 2019

- name: "wait for {{url}} to come up"
  uri:
    url: "{{url}}"
    method: GET
    status: 200
  register: _result
  until: _result.status == 200
  retries: 30 # retry X times  
  delay: 60 # pause for X sec b/w each call

max calls = retries + 1


TASK [URL CALL : wait for https://xxx to come up] ***
FAILED - RETRYING: wait for https://xxx to come up (30 retries left).
FAILED - RETRYING: wait for https://xxx to come up (29 retries left).
FAILED - RETRYING: wait for https://xxx to come up (28 retries left).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.