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:
- name: apt upgrade
shell: apt-get upgrade
Is there any way to see stdout and stderr ? I tried:
- name: apt upgrade
shell: apt-get upgrade
register: hello
- debug: msg="{{ hello.stdout }}"
- debug: msg="{{ hello.stderr }}"
but nothing changed.
I do have required permissions and I pass correct sudo password - other tasks that require sudo execute correctly.
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:
[ssh_connection]
ssh_args = -o ServerAliveInterval=n
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.