# Ansible hangs when running remote su command via  sshpass

**URL:** <https://forum.ansible.com/t/ansible-hangs-when-running-remote-su-command-via-sshpass/18993>\
**Category:** Ansible Project\
**Created:** [August 11, 2015, 11:36am UTC](https://forum.ansible.com/t/ansible-hangs-when-running-remote-su-command-via-sshpass/18993 "2015-08-11T11:36:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![firxiao\_zhang](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@firxiao\_zhang](https://forum.ansible.com/u/firxiao_zhang)\
**Post date:** [August 11, 2015, 11:36am UTC](https://forum.ansible.com/t/ansible-hangs-when-running-remote-su-command-via-sshpass/18993/1 "2015-08-11T11:36:44Z")

</div>

##### HI:

##### Ansible Version:

`  
[vagrant@master ansible]$ ansible --version

ansible 1.9.2

configured module search path = None

`

##### Environment:

client is same as master.

`  
[vagrant@master ansible]$ cat /etc/redhat-release  
CentOS release 6.6 (Final)

[vagrant@master ansible]$ locale

LANG=zh\_CN.UTF-8

LC\_CTYPE=“zh\_CN.UTF-8”

LC\_NUMERIC=“zh\_CN.UTF-8”

LC\_TIME=“zh\_CN.UTF-8”

LC\_COLLATE=“zh\_CN.UTF-8”

LC\_MONETARY=“zh\_CN.UTF-8”

LC\_MESSAGES=“zh\_CN.UTF-8”

LC\_PAPER=“zh\_CN.UTF-8”

LC\_NAME=“zh\_CN.UTF-8”

LC\_ADDRESS=“zh\_CN.UTF-8”

LC\_TELEPHONE=“zh\_CN.UTF-8”

LC\_MEASUREMENT=“zh\_CN.UTF-8”

LC\_IDENTIFICATION=“zh\_CN.UTF-8”

LC\_ALL=

`

**Problem:**

**when I run like this:**

`  
[vagrant@master ansible]$ ansible all -m shell -a ‘whoami’ -u vagrant --su --su-user=root --ask-su-pass -k -vvv  
SSH password:  
SU password[defaults to SSH password]:  
\<192.168.33.101\> ESTABLISH CONNECTION FOR USER: vagrant  
\<192.168.33.101\> REMOTE\_MODULE command whoami #USE\_SHELL  
\<192.168.33.101\> EXEC sshpass -d6 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r” -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o ConnectTimeout=10 192.168.33.101 /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1439290735.17-42884376805584 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1439290735.17-42884376805584 && echo $HOME/.ansible/tmp/ansible-tmp-1439290735.17-42884376805584’  
\<192.168.33.101\> PUT /tmp/tmpqXDswp TO /home/vagrant/.ansible/tmp/ansible-tmp-1439290735.17-42884376805584/command  
\<192.168.33.101\> EXEC sshpass -d6 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r” -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o ConnectTimeout=10 192.168.33.101 /bin/sh -c ‘su root -c “/bin/sh -c '”’“‘echo BECOME-SUCCESS-erjxmrwbinqrhshhjhnvurorvvvchdwu; LANG=C LC\_CTYPE=C /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1439290735.17-42884376805584/command; rm -rf /home/vagrant/.ansible/tmp/ansible-tmp-1439290735.17-42884376805584/ \>/dev/null 2\>&1’”‘"’"’

`

**it would hang here. and nothing happened.**

**but after add “-c paramiko” it worked fine.**

`  
[vagrant@master ansible]$ ansible all -m shell -a ‘whoami’ -u vagrant --su --ask-su-pass --su-user=root -k -vvv -c paramiko  
SSH password:  
SU password[defaults to SSH password]:  
\<192.168.33.101\> ESTABLISH CONNECTION FOR USER: vagrant on PORT 22 TO 192.168.33.101  
\<192.168.33.101\> REMOTE\_MODULE command whoami #USE\_SHELL  
\<192.168.33.101\> EXEC /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1439291679.85-56991589093799 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1439291679.85-56991589093799 && echo $HOME/.ansible/tmp/ansible-tmp-1439291679.85-56991589093799’  
\<192.168.33.101\> PUT /tmp/tmpI15Pt9 TO /home/vagrant/.ansible/tmp/ansible-tmp-1439291679.85-56991589093799/command  
\<192.168.33.101\> EXEC /bin/sh -c ‘su root -c “/bin/sh -c '”’“‘echo BECOME-SUCCESS-phfsumyntqcookmrpodqpvbtyrngtlgw; LANG=C LC\_CTYPE=C /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1439291679.85-56991589093799/command; rm -rf /home/vagrant/.ansible/tmp/ansible-tmp-1439291679.85-56991589093799/ \>/dev/null 2\>&1’”‘"’"’

node1 | success | rc=0 \>\>  
root  
`

**I have try**

`ansible all -m shell -a 'whoami' -u vagrant --become --ask-become-pass --become-method=su -k -vvv`  
**it would hang too.**

**but this worked fine.**

`ansible all -m shell -a 'whoami' -u vagrant --become --ask-become-pass --become-method=su -k -vvv -c paramiko`

**does “su command” can’t work with sshpass ? or this is a bug ?**

**thanks**

---

<div class="post-metadata">

**Author:** ![rakeshkumar.ram](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@rakeshkumar.ram](https://forum.ansible.com/u/rakeshkumar.ram)\
**Post date:** [August 18, 2016, 8:30pm UTC](https://forum.ansible.com/t/ansible-hangs-when-running-remote-su-command-via-sshpass/18993/2 "2016-08-18T20:30:04Z")

</div>

After struggling a lot with ansible getting hung I bumped up on this post and tried passing “-c paramiko” and it worked for me as well. Thanks for the post.  
I have the same query whether it is a bug or as designed ?
