# Shell script in handler

**URL:** <https://forum.ansible.com/t/shell-script-in-handler/23464>\
**Category:** Ansible Project\
**Created:** [January 16, 2017, 7:56am UTC](https://forum.ansible.com/t/shell-script-in-handler/23464 "2017-01-16T07:56:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shantanu\_Jain](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Shantanu\_Jain](https://forum.ansible.com/u/Shantanu_Jain)\
**Post date:** [January 16, 2017, 7:56am UTC](https://forum.ansible.com/t/shell-script-in-handler/23464/1 "2017-01-16T07:56:41Z")

</div>

Can I write a shell script in handler and call it again and again?

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@Anand\_Buddhdev](https://forum.ansible.com/u/Anand_Buddhdev)\
**Post date:** [January 16, 2017, 6:52pm UTC](https://forum.ansible.com/t/shell-script-in-handler/23464/2 "2017-01-16T18:52:50Z")

</div>

Hi Shantanu,

A handler is just like any other task, so you can use the “shell” module to run shell commands. If you script is small, you can just include it in-line, like this:

name: my script  
shell: |  
echo line 1  
echo more stuff {{ variable }}  
cd /some/dir  
do stuff  
if [condition]; then action; fi

Regards,  
Anand
