# How to set timeout value for a task using shell module?

**URL:** <https://forum.ansible.com/t/how-to-set-timeout-value-for-a-task-using-shell-module/29337>\
**Category:** Ansible Project\
**Created:** [December 28, 2018, 4:53pm UTC](https://forum.ansible.com/t/how-to-set-timeout-value-for-a-task-using-shell-module/29337 "2018-12-28T16:53:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [December 28, 2018, 4:53pm UTC](https://forum.ansible.com/t/how-to-set-timeout-value-for-a-task-using-shell-module/29337/1 "2018-12-28T16:53:51Z")

</div>

Hi Ansible Experts,  
We are running tasks using shell module. Sometime these tasks are pending due to backend application server slow response. Is there anyway to set timeout for these tasks to exit after certain time period?

Regards  
Saravanan

---

<div class="post-metadata">

**Author:** ![Piyush\_Bansal](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@Piyush\_Bansal](https://forum.ansible.com/u/Piyush_Bansal)\
**Post date:** [December 28, 2018, 4:54pm UTC](https://forum.ansible.com/t/how-to-set-timeout-value-for-a-task-using-shell-module/29337/2 "2018-12-28T16:54:39Z")

</div>

Have u explored async mode ??

---

<div class="post-metadata">

**Author:** ![S\_C\_Rigler](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@S\_C\_Rigler](https://forum.ansible.com/u/S_C_Rigler)\
**Post date:** [December 28, 2018, 6:16pm UTC](https://forum.ansible.com/t/how-to-set-timeout-value-for-a-task-using-shell-module/29337/3 "2018-12-28T18:16:54Z")

</div>

Assuming the target machine is running a modern Linux version, you can  
run the "timeout" command in your shell.

Like:

- shell: timeout -s 9 10 /usr/bin/command that does something

That will send a "kill -9" to the command if it doesn't finish in 10 seconds.

---

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [December 29, 2018, 8:35pm UTC](https://forum.ansible.com/t/how-to-set-timeout-value-for-a-task-using-shell-module/29337/4 "2018-12-29T20:35:56Z")

</div>

Thank you Steve.
