Last Updated: December 26, 2018
·
18.12K
· knightlabs

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.

1 Response
Add your response

over 1 year ago ·