ansible 2 ping failure

Hi Guys,
I’m having some trouble with the new Ansible 2 when trying to run ping on a host that works with 1.9.4.

I’m getting the following:

$ ansible -i test all -m ping -u root -vvvvv -c paramiko

Loaded callback minimal of type stdout, v2.0
<10.10.0.242> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO 10.10.0.242
<10.10.0.242> EXEC mkdir -p “$( echo $HOME/.ansible/tmp/ansible-tmp-1452643119.18-173252181839542 )” && echo “$( echo $HOME/.ansible/tmp/ansible-tmp-1452643119.18-173252181839542 )”
<10.10.0.242> PUT /var/folders/1d/nqrbvtz120nb7r2rjqzpvs7m0000gn/T/tmpjR2gSS TO /home/root/.ansible/tmp/ansible-tmp-1452643119.18-173252181839542/ping
<10.10.0.242> EXEC LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/root/.ansible/tmp/ansible-tmp-1452643119.18-173252181839542/ping; rm -rf “/home/root/.ansible/tmp/ansible-tmp-1452643119.18-173252181839542/” > /dev/null 2>&1
10.10.0.242 | FAILED! => {
“changed”: false,
“failed”: true,
“invocation”: {
“module_name”: “ping”
},
“module_stderr”: “”,
“module_stdout”: “\u001b[?1034h{"invocation": {"module_args": {"data": null}}, "changed": false, "ping": "pong"}\r\n”,
“msg”: “MODULE FAILURE”,
“parsed”: false
}

Previously on 1.9.4 I would get:

$ ansible -i test all -m ping -u root -vvvvv -c paramiko
<10.10.0.242> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO 10.10.0.242
<10.10.0.242> REMOTE_MODULE ping
<10.10.0.242> EXEC /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1452643204.88-178243528154466 && echo $HOME/.ansible/tmp/ansible-tmp-1452643204.88-178243528154466’
<10.10.0.242> PUT /var/folders/1d/nqrbvtz120nb7r2rjqzpvs7m0000gn/T/tmpqHPWsg TO /home/root/.ansible/tmp/ansible-tmp-1452643204.88-178243528154466/ping
<10.10.0.242> EXEC /bin/sh -c ‘LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/root/.ansible/tmp/ansible-tmp-1452643204.88-178243528154466/ping; rm -rf /home/root/.ansible/tmp/ansible-tmp-1452643204.88-178243528154466/ >/dev/null 2>&1’
10.10.0.242 | success >> {
“changed”: false,
“ping”: “pong”
}

Any idea what the culprit might be? At first glance the only real difference I can see is that the older version had /bin/sh -c in front, but that could just be a change in logging.

Cheers

Hrm, looks like there’s some garbage in front of the result. Can you open a github issue for this, with details on the target system included?

Looks like your shell is injecting control characters into the output
stream. (the initial junk is a terminal control code sequence:
ESC[?1034h ). We'll probably need information about the shell you're
using on the remote machine and its configuration.

-Toshio

I’m having a similar issue:

`
$ ansible -i inventory crcweb -m ping -vvv
Using /home/jurgenhaas/.ansible.cfg as config file
ESTABLISH SSH CONNECTION FOR USER: jurgenhaas
SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=jurgenhaas -o ConnectTimeout=10 -o ControlPath=/home/jurgenhaas/.ansible/cp/ansible-ssh-%h-%p-%r -tt crcweb ‘( umask 22 && mkdir -p “$( echo $HOME/.ansible/tmp/ansible-tmp-1452763749.58-212919486518705 )” && echo “$( echo $HOME/.ansible/tmp/ansible-tmp-1452763749.58-212919486518705 )” )’
PUT /tmp/tmpEhWM_e TO ^/ping
SSH: EXEC scp -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=jurgenhaas -o ConnectTimeout=10 -o ControlPath=/home/jurgenhaas/.ansible/cp/ansible-ssh-%h-%p-%r /tmp/tmpEhWM_e ‘[crcweb]:’“'”’ ^/ping’“'”‘’
crcweb | FAILED! => {
“failed”: true,
“msg”: “ERROR! failed to transfer file to ^/ping:\n\nscp: ^/ping: No such file or directory\n”
}

`

On the remote hosts we are using the fish shell instead of bash or others and that seems to be the root of the problem. When changing to bash as the login shell, Ansible would work just fine, but that’s not really an option.

Reported at GitHub: https://github.com/ansible/ansible/issues/13882

I’ll check out the github issue, but I just wanted to post back here.

I narrowed down the issue to being related to the local TERM environment variable (xterm-256color). Because my local terminal was consuming the garbage characters when I was running the ping command remotely, the only way to see the escape characters is to redirect to a file &> out and you’ll see them there (it took a moment to realize what was going on because originally I was just running the python ping command by hand and I wasn’t seeing the starting escape characters).

If you plaster TERM=vt100 in front of any of your ansible commands things work great and the ping command works.
Another interesting thing to note is that if you enable pipelining=true in your ansible.cfg, you don’t need TERM=vt100 to be set.

I didn’t think sending my local term was intended - I was able to track down the issue in the paramiko code (it calls os.sys to get the local term) but I couldn’t find the corresponding openssh issue.

Cheers

@abadger opened up an issue for my particular problem:

https://github.com/ansible/ansible/issues/13895

cheers!