Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have Ansible retry on connection failure?

I am facing this annoying bug: Ansible hosts are randomly unreachable #18188 .

Is there a way to tell Ansible that if SSH connection fails, to try it once more? Or 2 times more?

According this post New SSH Retry In Ansible 2.0? there is "retries" option but it doesn't seem very trustworthy to me, the person who posted didn't even get SSH header right and there is no mention of this in Ansible docs.

like image 315
Petr Avatar asked Oct 31 '16 10:10

Petr


People also ask

What is .retry file in Ansible?

retry file. When playbooks fail to run against a host Ansible creates a retry file name 'hostname. retry. ' The file outlines the problem Ansible had running the play.

Which connection methods does Ansible use?

By default, Ansible ships with several connection plugins. The most commonly used are the paramiko SSH, native ssh (just called ssh), and local connection types. All of these can be used in playbooks and with /usr/bin/ansible to decide how you want to talk to remote machines.

Can I use Ansible without SSH?

Ansible can use a variety of connection methods beyond SSH. You can select any connection plugin, including managing things locally and managing chroot, lxc, and jail containers.


1 Answers

Yes, it is possible using the method which you referenced in your question, i.e. by placing the following parameter in ansible.cfg:

[ssh_connection]
retries=2
  • Here is the line that reads retries from ansible.cfg
  • Here is the loop that performs retrying
like image 81
techraf Avatar answered Sep 22 '22 11:09

techraf