I’m trying to use ansible to configure the environment I have to use. In particular, I need to write a task that reboots the servers, so I wrote this task:
- name: waiting for server to come back local_action: wait_for host={{ ansible_hostname }} port=22 state=started delay=50 timeout=300 sudo: false
but the task fails reaching the time-out even though servers are correctly restarted.
I was wondering if it fails because of my ssh configuration. The connection to these servers is done through a Proxy (ProxyCommand
in ~/.ssh/config
).
FROM VERBOSE OUTPUT <servername> ESTABLISH SSH CONNECTION FOR USER: username <servername> SSH: EXEC ssh -C -vvv -o ControlMaster=False -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=username -o ConnectTimeout=10 -tt hostname ... fatal: [servername -> localhost]: FAILED! => {"changed": false, "elapsed": 300, "failed": true, "invocation": {"module_args": {"connect_timeout": 5, "delay": "10", "exclude_hosts": null, "host": "hostname", "path": null, "port": "22", "search_regex": null, "state": "started", "timeout": "300"}, "module_name": "wait_for"}, "msg": "Timeout when waiting for host:22"}
I don’t know if relevant but in the output:
hostname != servername: hostname = foo, servername = foo.bar.com
I think hostname=ansible_hostname
while servername=inventory_hostname
Ansible version: ansible 2.0.1.0
Advertisement
Answer
It was a connectivity problem. To get rid of this problem I’ve increased the ssh timeout.
One simple way to do that it’s creating a ansible.cfg
file in the same directory of the ansible script and put inside this content:
[defaults] timeout = xx
where xx for me was 30.