How to detect why Ansible playbook hangs during execution

Question:

Some of tasks I wrote start and never end. Ansible does not provide any errors or logs that would explain this, even with -vvvv option. Playbook just hangs and passing hours doesn’t change anything.

When I try to run my tasks manually (by entering commands via SSH) everything is fine.

Example task that hangs:

Is there any way to see stdout and stderr ? I tried:

but nothing changed.

I do have required permissions and I pass correct sudo password – other tasks that require sudo execute correctly.

Answer:

Most Probable cause of your problem would be SSH connection. When a task requires a long execution time SSH timeouts. I faced such problem once, in order to overcome the SSH timeout thing, create a ansible.cfg in the current directory from which your are running Ansible add the following:

Where n is the ServerAliveInterval (seconds) which we use while connecting to the server through SSH. Set it between 1-255. This will cause ssh client to send null packets to server every n seconds to avoid connection timeout.

Leave a Reply