# Simple Shell Command not executing

**URL:** <https://forum.ansible.com/t/simple-shell-command-not-executing/36088>\
**Category:** Ansible Project\
**Created:** [December 9, 2021, 3:03am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088 "2021-12-09T03:03:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradipto\_dasgupta](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pradipto\_dasgupta](https://forum.ansible.com/u/pradipto_dasgupta)\
**Post date:** [December 9, 2021, 3:03am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088/1 "2021-12-09T03:03:10Z")

</div>

Hello All,

I am new in Ansible and was trying to execute a shell script in one of the remote hosts. The script runs fine when executed directly from the host. It is a simple shell script to create a folder.

The shell script is

---

<div class="post-metadata">

**Author:** ![pradipto\_dasgupta](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pradipto\_dasgupta](https://forum.ansible.com/u/pradipto_dasgupta)\
**Post date:** [December 9, 2021, 3:29am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088/2 "2021-12-09T03:29:40Z")

</div>

I can get the script run if I use the “command” module in the yml file

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [December 9, 2021, 7:46am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088/3 "2021-12-09T07:46:27Z")

</div>

That shell script is not in your PATH. If you just created the  
script, you should use "cmd: ./create\_new\_folder\_pradipto.sh"

---

<div class="post-metadata">

**Author:** ![sarbajit\_das](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sarbajit\_das](https://forum.ansible.com/u/sarbajit_das)\
**Post date:** [December 11, 2021, 12:11am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088/4 "2021-12-11T00:11:29Z")

</div>

Hi Pradipto,  
As you can see the error says _“create\_new\_folder.sh: command not found”_.

Just a little addition will resolve this issue.

The yml file is

---

<div class="post-metadata">

**Author:** ![Parveen\_Datt](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@Parveen\_Datt](https://forum.ansible.com/u/Parveen_Datt)\
**Post date:** [December 11, 2021, 12:32am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088/5 "2021-12-11T00:32:22Z")

</div>

Better use script module

- name: Execute shell script  
script: create\_new\_folder\_pradipto.sh

---

<div class="post-metadata">

**Author:** ![pradipto\_dasgupta](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@pradipto\_dasgupta](https://forum.ansible.com/u/pradipto_dasgupta)\
**Post date:** [December 11, 2021, 12:42am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088/6 "2021-12-11T00:42:15Z")

</div>

Thank you all. Eventually I realized I should be using “script” instead of “shell”

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [December 11, 2021, 8:31am UTC](https://forum.ansible.com/t/simple-shell-command-not-executing/36088/7 "2021-12-11T08:31:17Z")

</div>

Keep in mind

[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/script\_module.html#notes](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/script_module.html#notes)

- It is usually preferable to write Ansible modules rather than pushing scripts. Convert your script to an Ansible module for bonus points!

Since your script just creates a directory that can be better done using an ansible file task.
