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.
Playbook hangs indefinitely when gather_tasks is enabled (the default) meaning that Ansible cannot get past the initial setup module.
Just run the task service: name=httpd state=started with the option --check .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With