Looking for a Way to Set a Global Task Timeout in Ansible

Ahhh, that explains it. This feature was added in ansible 2.10 added 'task timeout' feature (#69284) · ansible/ansible@df4e83d · GitHub. There is no global timeout in 2.9.

Can i upgrade version to 2.17.0 core? And one more thing i have looked into few blogs does this works for any ansible task like shell, command will this work. Is global_task_timeout, possible to achieve for the ansible tasks which are running through shell, commands. Please help me with this, does this require manual work to add varibales in each ansible roles or if i define in ansible.cfg globally will it pick. I was going across many blogs one way i found out this, which is working but not feasible →

“timeout 5s ansible-playbook -i inventory test.yaml”

Help me to achieve with task_timeout usage

You need Python 3.10 (or 3.11 or 3.12) to run ansible 2.17. You can see the Python requirements here Releases and maintenance — Ansible Community Documentation.

There are lots of ways to install, Ansible, I recommend starting here Installing Ansible — Ansible Community Documentation.

Here’s one way:

Run ansible --version to check the install worked

$ ansible --version
ansible [core 2.17.11]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/shertel/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/shertel/projects/dev/venvs/python310_ansible217/lib64/python3.10/site-packages/ansible
  ansible collection location = /home/shertel/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/shertel/projects/dev/venvs/python310_ansible217/bin/ansible
  python version = 3.10.13 (main, Aug 28 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/shertel/projects/dev/venvs/python310_ansible217/bin/python3.10)
  jinja version = 3.1.6
  libyaml = True

Then you should be able to see the timeout is configured with ansible-config dump --only-changed:

CONFIG_FILE() = /etc/ansible/ansible.cfg
EDITOR(env: EDITOR) = /usr/bin/nano
TASK_TIMEOUT(/etc/ansible/ansible.cfg) = 2

We are bound to use this ansible version, please confirm.
ansible [core 2.17.0]
config file = None
configured module search path = [‘/home/kubenode/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
ansible collection location = /home/kubenode/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.12.1 (main, Feb 21 2024, 10:25:11) [GCC 8.5.0 20210514 (Red Hat 8.5.0-21)] (/usr/bin/python3)
jinja version = 3.1.6
libyaml = True

ansible-playbook -i inventory test.yaml -vv
ansible-playbook [core 2.17.0]
config file = /home/kubenode/sprint25_new_load/ansible.cfg
configured module search path = [‘/home/kubenode/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
ansible collection location = /home/kubenode/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.12.1 (main, Feb 21 2024, 10:25:11) [GCC 8.5.0 20210514 (Red Hat 8.5.0-21)] (/usr/bin/python3)
jinja version = 3.1.6
libyaml = True
Using /home/kubenode/sprint25_new_load/ansible.cfg as config file
Skipping callback ‘default’, as we already have a stdout callback.
Skipping callback ‘minimal’, as we already have a stdout callback.
Skipping callback ‘oneline’, as we already have a stdout callback.

PLAYBOOK: test.yaml ******************************************************************************************************************************************
1 plays in test.yaml

PLAY [localhost] *********************************************************************************************************************************************

TASK [Run a longer task with its own timeout] ****************************************************************************************************************
task path: /home/kubenode/sprint25_new_load/test.yaml:5
fatal: [127.0.0.1]: FAILED! => {“changed”: false, “msg”: “The command action failed to execute in the expected time frame (2) and was terminated”}

PLAY RECAP ***************************************************************************************************************************************************
127.0.0.1 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

1 Like