# Getting command not found when executing using shell module

**URL:** <https://forum.ansible.com/t/getting-command-not-found-when-executing-using-shell-module/32483>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [March 17, 2020, 7:29am UTC](https://forum.ansible.com/t/getting-command-not-found-when-executing-using-shell-module/32483 "2020-03-17T07:29:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [March 17, 2020, 7:29am UTC](https://forum.ansible.com/t/getting-command-not-found-when-executing-using-shell-module/32483/1 "2020-03-17T07:29:46Z")

</div>

> Here is my playbook:
> 
> cat test.yml
> 
> \>  
> -name:Play2  
> 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:
> 
> \>  
> 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.
> 
> Can you please help overcome this issue ?

Ansible is running the shell non-interactive, thus it uses a different environment.

Possible solutions:

- Use full paths for ip / ipconfig  
- Define PATH in your script  
- Define PATH in env parameter in your task

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
