Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase timeout of SSH command in Ansible

Tags:

ssh

ansible

I am currently using Ansible to provision bare metal using an IPv6 link local address. Once the servers are provisioned, ansible will run a series of tests on the server, as one shell command, to ensure provisioning was successful. These tests take approximately 10 minutes to run.

The issue that I'm facing is that the connection seems to timeout before the command completes.

Here is the error from Ansible:

fatal: [fe80::5054:ff:XXXX:XXXX%eth0]: UNREACHABLE! => {
  "changed": false, 
  "msg": "Failed to connect to the host via ssh: Shared connection to fe80::5054:ff:XXXX:XXXX%eth0 closed.\r\n",
  "unreachable": true
}

By looking at this error, one might think there is an issue with the SSH connection. The SSH connection itself is good since several other tasks run successfully on the same host prior to this task.

How can I increase the timeout so that Ansible will wait for the command to finish? Can this timeout be increased within the Ansible configuration, or do I need to modify the command itself to increase the timeout?

like image 917
grizzthedj Avatar asked Apr 06 '17 16:04

grizzthedj


1 Answers

You're going to want to run the task asynchronously. High-level steps would be:

  1. send deployment request for instance
  2. get some kind of instance or request id for said request
  3. poll for result of request
  4. continue playbook

here's an example of this behaviour from the official docs

- name: 'YUM - fire and forget task'
  yum:
    name: docker-io
    state: installed
  async: 1000
  poll: 0
  register: yum_sleeper

- name: 'YUM - check on fire and forget task'
  async_status:
    jid: "{{ yum_sleeper.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  retries: 30
  delay: 10
like image 82
Camilo Santana Avatar answered Nov 20 '22 20:11

Camilo Santana