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.
Written by John Knight
Related protips
1 Response
new syntax with 1.4:
https://gist.github.com/amiorin/f566f25638d6289231eb
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Status
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#