Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect why Ansible playbook hangs during execution

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.

like image 733
dev9 Avatar asked Dec 27 '13 10:12

dev9


People also ask

Why is my Ansible-playbook hanging indefinitely with no progress past fact gathering?

Playbook hangs indefinitely when gather_tasks is enabled (the default) meaning that Ansible cannot get past the initial setup module.

How do I check the status of Ansible-playbook?

Just run the task service: name=httpd state=started with the option --check .

How do you handle long running tasks in Ansible?

For a long running task use Ansible's Asynchronous mode to effectively background the task. Then follow it up with another task that checks the status of the backgrounded task.

What does Ansible-playbook -- check do?

Using Ansible's dry run feature enables users to execute a playbook without making changes to the servers. It uses the built-in check mode to proof a playbook for errors before execution. This option is very useful when executing complex playbooks that contain commands which make major changes to servers.


1 Answers

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.

like image 109
Abhijit Avatar answered Sep 27 '22 23:09

Abhijit