-
-
Save mikeifomin/67e233cd461331de16707ef59a07e372 to your computer and use it in GitHub Desktop.
- name: wait_for http | |
command: "curl --silent {{ url }}" | |
register: result | |
until: result.stdout.find("200 OK") != -1 | |
retries: 60 | |
delay: 1 | |
changed_when: false |
@realjiktu nice workaround. But... version with
curl
is more reliable.uri
depends onhttplib2
python library which must be installed on remote host.
https://docs.ansible.com/ansible/latest/modules/uri_module.html#notes
The dependency on httplib2 was removed in Ansible 2.1
The uri module doesn't work for me. I'm deploying a mucroservice on our Kubernetes cluster and have to make additional calls, after the service is reachable. The issue with the uri module is, the dns entry is created when the microservice is deployed. It take up to 2-3 minutes until it is created. The uri module failes, if the dns entry hasn't been created when it's executed. So I'll try the curl/command module thing mentioned above. Does anybody has another idea for this?
Here is a variation of the above that works. Since this constantly returns a 200 it checks content instead. Similar to the above examples you can add status_code: [200, 403]
if the health check returns a 200 or a 403 as passing and check that in the until
portion.
- name: wait for consul to come up
uri:
url: "http://127.0.0.1:8500/v1/status/leader"
method: GET
headers:
Authorization: Bearer {{ consul_acl_master_token }}
return_content: yes
register: _result
until: _result.content != '\"\"'
retries: 30 # retry X times
delay: 3 # pause for X sec b/w each call
The dependency on httplib2 was removed in Ansible 2.1
And it can be run as a local action on the ansible-host, instead of the target host.
(Unless your network setup forbids ansible to reach the target url)
- name: Wait for frontend at {{ somewhere }} to come up
local_action:
module: uri
url: "{{ somewhere }}"
status_code: 200
register: result
[...]
max calls = retries + 1