# getting command not found error when using ansible shell module to execute shell script.

**URL:** <https://forum.ansible.com/t/getting-command-not-found-error-when-using-ansible-shell-module-to-execute-shell-script/32482>\
**Category:** Ansible Project\
**Created:** [March 17, 2020, 7:11am UTC](https://forum.ansible.com/t/getting-command-not-found-error-when-using-ansible-shell-module-to-execute-shell-script/32482 "2020-03-17T07:11:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [March 17, 2020, 7:11am UTC](https://forum.ansible.com/t/getting-command-not-found-error-when-using-ansible-shell-module-to-execute-shell-script/32482/1 "2020-03-17T07:11:59Z")

</div>

Here is my playbook:

cat test.yml

`- name: Play 2`  
`hosts: targetserver`  
`tasks:`

`- copy: src=./centosscript.sh dest=~ mode=775`  
`- shell: ~/centosscript.sh`

Here is my shell script:

cat centosscript.sh  
`#/bin/ksh`  
`grabip=`ip r | grep kernel``

I also tried

`grabip=`ifconfig | grep inet``

cat myhosts  
`[targetserver]`  
`10.9.9.26`

I get the following error when i run the playbook:

`$ ansible-playbook -i myhosts test.yml`  
`TASK [copy] ************************************************************************************************************************************************* `  
`changed: [10.9.9.26]`

`TASK [shell] ************************************************************************************************************************************************ `  
`fatal: [10.9.9.26]: FAILED! => {"changed": true, "cmd": "~/centosscript.sh", "delta": "0:00:00.122291", "end": "2020-03-17 12:18:49.485014", "msg": "non-zero return code", "rc": 1, "start": "2020-03-17 12:18:49.362723", "stderr": "/home/user1/centosscript.sh: line 2: ip: command not found", "stderr_lines": ["/home/user1/centosscript.sh: line 2: ip: command not found"], "stdout": "", "stdout_lines": []}`

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

When i run ip r or ifconfig commands they work fine on the target server.

I need to use ksh shell. However, i get the same error even if i try #/bin/bash in my shell script. Below is the output of the same commands working fine with the ksh shell on the target server.

`bash-4.2$ ksh $ ip r | grep kernel 10.9.9.0/24 dev eth0 proto kernel scope link src 10.9.9.26 metric 100 $ ifconfig | grep inet inet 10.9.9.26 netmask 255.255.255.0 broadcast 10.9.9.255`

Can you please help overcome this issue ?
