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,230 points

1 answer to this question.

0 votes

Got it working using wait_for and until statement together:

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