24

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.

techraf
  • 64,883
  • 27
  • 193
  • 198
Petr
  • 13,747
  • 20
  • 89
  • 144

1 Answers1

36

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
techraf
  • 64,883
  • 27
  • 193
  • 198
  • But it's looking for `ssh_connection` so why everyone keep posting `ssh-connection`? – Petr Oct 31 '16 at 21:04
  • 10
    And why are you asking me? If you think it should be, then write it and submit a pull request. – techraf Oct 31 '16 at 21:11
  • 2
    Note that setting retries in the [ssh_connection] section, will *retry the particular ssh command*, not the ansible step. Many ansible module commands are implemented as a series of ssh commands. If there is a connection error in the middle of these steps, ansible will retry the last executed SSH command. Depending on what that step does, it might not be idempotent, and you can get errors like "No such file: /home/me/.ansible/tmp/abcdef". It would be nice to to have ansible retry the entire step (with all ssh subcommands) on connection errors. – Daniel Abrahamsson Mar 30 '17 at 06:32
  • 9
    it is also possible to define the environment variable [ANSIBLE_SSH_RETRIES](http://docs.ansible.com/ansible/latest/reference_appendices/config.html?highlight=retry#envvar-ANSIBLE_SSH_RETRIES) – Baptiste Mille-Mathias May 31 '18 at 06:24
  • 1
    is there a way to specify an interval between retries? – paragm Jul 01 '18 at 05:44
  • @paragm Not without modifying the code under the second link. – techraf Jul 01 '18 at 05:52