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
2,408 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, 2019 in Ansible by Anushri
587 views
0 votes
1 answer

How do I wget a file from web server using shell in the ansible playbook

Hey Ayaan, you could probably use this ...READ MORE

answered Jan 24, 2019 in Ansible by Anushri
3,863 views
0 votes
1 answer

How to install httpd web server in remote node using Ansible?

Hi@akhtar, You need to use the package module in Ansible. ...READ MORE

answered Jul 30, 2020 in Ansible by MD
• 95,440 points
2,218 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
3,143 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,507 views
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
6,546 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
14,039 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP