# how to set timeout for shell command

**URL:** <https://forum.ansible.com/t/how-to-set-timeout-for-shell-command/16228>\
**Category:** Ansible Project\
**Created:** [September 15, 2014, 3:36pm UTC](https://forum.ansible.com/t/how-to-set-timeout-for-shell-command/16228 "2014-09-15T15:36:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jinsik\_Kim](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Jinsik\_Kim](https://forum.ansible.com/u/Jinsik_Kim)\
**Post date:** [September 15, 2014, 3:36pm UTC](https://forum.ansible.com/t/how-to-set-timeout-for-shell-command/16228/1 "2014-09-15T15:36:59Z")

</div>

Hi,

I want to define response waiting time limit for all shell commands on ansible-playbook

test.yml:  
…

- name: want to quit if it doesn’t get response in 5 secs  
shell: “sleep 100”

- name: want to quit if it doesn’t get response in 5 secs  
shell: “sleep 200”

- name: want to quit if it doesn’t get response in 5 secs  
shell: “sleep 300”

…

I know I can use async method for each task but is there any simple way to do this for all shell module command?

I’ve tried this but it didn’t work

> ansible-playbook test.yml … -T 50  
> add timeout=10 on ansible.cfg

Thanks in advance,  
Justin

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [September 15, 2014, 8:33pm UTC](https://forum.ansible.com/t/how-to-set-timeout-for-shell-command/16228/2 "2014-09-15T20:33:57Z")

</div>

Hi Justin, currently there is no general purpose timeout parameter for shell/commands, so the use of async as you’ve noted is the proper way to limit the execution time of a long-running task.

Thanks!

---

<div class="post-metadata">

**Author:** ![jorginator74](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@jorginator74](https://forum.ansible.com/u/jorginator74)\
**Post date:** [September 22, 2014, 8:52am UTC](https://forum.ansible.com/t/how-to-set-timeout-for-shell-command/16228/3 "2014-09-22T08:52:19Z")

</div>

Hi
