Ansible task timeout max length

Weighing in on this in case someone comes across it, there was a timeout option added in a later version which allows you to specify the following variables in your inventory file on WinRM instances:

ansible_winrm_operation_timeout_sec: 120
ansible_winrm_read_timeout_sec: 150

My use case was a docker swarm init which is pretty messy on Windows but performs fine on Linux. It didn't resolve my issue but it may resolve yours depending on your transport.

I did also note https://github.com/ansible/ansible/pull/69284/files but this isn't explained anywhere that I could find.


There is no timeout-for-a-task-functionality implemented in Ansible.

You can try a workaround using asynchronous call, but for this case (clearly a kind of a bug) relying on the system might be easier and more appropriate.

See the GNU timeout command (if you run Docker, chances are the command is present on your OS):

shell: timeout 5m docker ps ...

A task timeout is added in 2.10 release, which is useful in such scenario.

https://github.com/ansible/ansible/issues/33180

https://github.com/ansible/ansible/pull/69284

For example, below playbook fails in 2.10 version:

---
- hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - shell: |
      while true; do
        sleep 1
      done
    timeout: 5
...

with an error message like:

TASK [shell] **************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "The shell action failed to execute in the expected time frame (5) and was terminated"}

Tags:

Docker

Ansible