# Eliminate /bin/sh -c environment from any ssh command sending.

**URL:** <https://forum.ansible.com/t/eliminate-bin-sh-c-environment-from-any-ssh-command-sending/31083>\
**Category:** Ansible Project\
**Created:** [August 21, 2019, 7:04am UTC](https://forum.ansible.com/t/eliminate-bin-sh-c-environment-from-any-ssh-command-sending/31083 "2019-08-21T07:04:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Van\_de\_Velde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tom_van_de_velde/32/10548_2.png) [@Tom\_Van\_de\_Velde](https://forum.ansible.com/u/Tom_Van_de_Velde)\
**Post date:** [August 21, 2019, 7:04am UTC](https://forum.ansible.com/t/eliminate-bin-sh-c-environment-from-any-ssh-command-sending/31083/1 "2019-08-21T07:04:07Z")

</div>

Hi,

I"m writing a module for Ansible, executing ssh commands on the a remote secured shell.  
Python is not installed and the installation is not possible.  
But It seams that there is always an attempt to discover the python on the remote.

Attempting python interpreter discovery  
 ESTABLISH SSH CONNECTION FOR USER: padmin  
 SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ‘User=“padmin”’ -o ConnectTimeout=10 -o ControlPath=/home/user/.ansible/cp/7c17f9a5a6 system ‘/bin/sh -c ‘"’“'echo PLATFORM; uname; echo FOUND; command -v '”’“'”‘"’“'”‘"’“‘/usr/bin/python’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘python3.7’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘python3.6’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘python3.5’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘python2.7’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘python2.6’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘/usr/libexec/platform-python’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘/usr/bin/python3’”‘"’“'”‘"’“'”‘"’; command -v ‘"’“'”‘"’“'”‘"’“‘python’”‘"’“'”‘"’“'”‘"’; echo ENDFOUND && sleep 0’“'”‘’  
 (1, b’‘, b’rksh: /bin/sh: 0403-019 The operation is not allowed in a restricted shell.\n’)  
 Failed to connect to the host via ssh: rksh: /bin/sh: 0403-019 The operation is not allowed in a restricted shell.

The error is there because even /bin/sh -c is not allowed.

By using the raw module, the “/bin/sh -c” is not used, so this might be an option, but the output using a raw is to complicated to be parsed in Ansible only so i would like to create a separate module for that.

Any suggestions here ??

Regards,  
Tom Van de Velde

---

<div class="post-metadata">

**Author:** ![Stephen\_Maher](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@Stephen\_Maher](https://forum.ansible.com/u/Stephen_Maher)\
**Post date:** [August 21, 2019, 9:01am UTC](https://forum.ansible.com/t/eliminate-bin-sh-c-environment-from-any-ssh-command-sending/31083/2 "2019-08-21T09:01:50Z")

</div>

Hi Tom,

How are you connecting to the VIOS ?? can you share a snippet of code - I’m looking at doing something similar for a storwize module for a platform refresh. My thoughts where to somehow use the connection module network\_cli ansible\_connection=network\_cli

Regards

---

<div class="post-metadata">

**Author:** ![Andrew\_Feller](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Andrew\_Feller](https://forum.ansible.com/u/Andrew_Feller)\
**Post date:** [August 21, 2019, 9:22am UTC](https://forum.ansible.com/t/eliminate-bin-sh-c-environment-from-any-ssh-command-sending/31083/3 "2019-08-21T09:22:58Z")

</div>

It might be prudent to study the Ansible modules in source code if you know you need to go this route:

[https://github.com/ansible/ansible/tree/devel/lib/ansible/modules](https://github.com/ansible/ansible/tree/devel/lib/ansible/modules)

Specifically the network category as most network devices don’t allow SSH access or have Python installed.

HTH, Andy

---

<div class="post-metadata">

**Author:** ![Tom\_Van\_de\_Velde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tom_van_de_velde/32/10548_2.png) [@Tom\_Van\_de\_Velde](https://forum.ansible.com/u/Tom_Van_de_Velde)\
**Post date:** [August 22, 2019, 6:11am UTC](https://forum.ansible.com/t/eliminate-bin-sh-c-environment-from-any-ssh-command-sending/31083/4 "2019-08-22T06:11:53Z")

</div>

Hi,

Currently this is very basic but working with raw and later parsing via yml template…

- name: RAW command  
raw: “ioscli lsrep”  
register: raw\_library  
changed\_when: false

- name: Parse raw output  
set\_fact:  
library: “{{ raw\_library.stdout | parse\_cli(‘parsers/lsrep.yml’) }}”

Regards,  
Tom
