i6ro4q
Last Updated: February 25, 2016
·
11.55K
· knightlabs
4ddba78516cc49157bbb21b09c14993e

Make Ansible wait for long-starting servers with a status check

The wait_for simply waits for the port to respond; if you're running long-starting web applications in a container like Tomcat or Jetty, wait_for might come back quickly, but the actual application won't be running yet;

Use URI + async/poll on your webapp's status page to look for an actually valid response:

- command: pkill -u tomcat
- service: name=tomcat state=started enabled=yes
- wait_for: port=8080 delay=10
- uri: url=http://localhost:8080/webapp/amiup status_code=200 timeout=300
  async: 300
  poll: 10
  register: amiup
- fail
   when: 'ok' not in "{{ amiup.content }}"

Note, the URI timeout has to match the async or you'll run into URI failing before the async finishes.

Say Thanks
Respond

1 Response
Add your response

12388
40d7a97fab50680b4a8fb3f3c882b101
over 1 year ago ·
Filed Under