Testing server response with timeout using ansible

0 votes

I have 2 servers hosting a website. I want to do a rolling upgrade with Ansible like the following:

I want roll out updates to my two servers with ansible. I want them to upgrade one at a time-> then take the building node off the load balancer-> run the tasks. Over here I want to wait it for server start up and send a request to a test URL 5 seconds periodically till there's a valid response. Here it fails the tasks because a timeout occurs after 3 minutes. I want these tasks to complete successfully and then build the next node.

I can do the timeout part with a custom script but isn't there some ansible functionality that does it automatically.

Aug 7, 2018 in Ansible by Atul
• 10,240 points
215 views

1 answer to this question.

0 votes

Got it working using wait_for and until statement together:

 - name: "wait for port to be available"
    wait_for:
      host: "127.0.0.1"
      port: "{{port}}"
      timeout: 30
  - name: "wait for web app to start up"
    shell: curl -XGET --head --silent http://127.0.0.1:{{port}}/test
    register: result
    until: result.stdout.find("200 OK") != -1
    retries: 60
    delay: 3
answered Aug 7, 2018 by Atul
• 10,240 points

Related Questions In Ansible

0 votes
1 answer

Mention Kubernetes version while using it with ansible

Hey @Dustin, The default value for roles is kube_version: ...READ MORE

answered Jan 22 in Ansible by Anushri
12 views
0 votes
1 answer
0 votes
2 answers

Issue creating AWS VPC with Ansible

You can use the details given in ...READ MORE

answered Aug 16, 2018 in Ansible by Priyaj
• 56,160 points
134 views
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
950 views
+13 votes
2 answers
0 votes
1 answer

How to use Ansible git module pull a branch with local changes?

You cannot achieve it using the git ...READ MORE

answered Jul 9, 2018 in Ansible by Atul
• 10,240 points
1,060 views
+1 vote
1 answer

Is it possible to append a large amount of text to a file using Ansible?

Here is concept which you can follow. blockinfile is ...READ MORE

answered Jul 30, 2018 in Ansible by Atul
• 10,240 points
1,876 views