SYNOPSIS
I was getting the following error when trying to run both the standard ansible all -m ping
and ansible all -a "pwd"
(The second command is just in the case the ping module was the issue):
..."module_stdout": " File \"/tmp/ansible_C2IrV6/ansible_module_command.py\", line 183\r\n out = b''\r\n ^\r\nSyntaxError: invalid syntax\r\n",...
My issue was that I was somehow running an unreleased Ansible version (2.4.0) due to installation via pip
. This was conflicting with my yum
installation (2.3.1.0), compounded by an incompatibility with my current Python version (2.6.6).
My solution was to uninstall both versions to ensure I no longer had ansible on my system. From there, I used yum
to reinstall ansible to a version that I knew was compatible (2.3.1.0). I have also read that it's possible to use pip
to specify the version:
pip install ansible==<version>
There are more details on installing different versions here
ORIGINAL POST
I've seen many instances where people seem to have my exact issue, but it always ends up being something slightly different. Regardless, I attempt the solutions to no avail.
I'm running Ansible 2.4.0 on what I believe is RHEL6:
$ uname -a
Linux <server address> 2.6.32-642.11.1.el6.x86_64 #1 SMP Wed Oct 26 10:25:23 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
The host I'm communicating with is running RHEL5.
When I run this command:
$ sudo ansible all -a "pwd" -vvvv
I get the following result:
Extracting the ssh command from the above output:
$ ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath=~/.ansible/cp' user@hostDestination '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
Result:
Extracted Ansible SSH Command Output
Based on the result above, it seems like the command makes a successful connection, so I don't see why Ansible is giving me the Permission Denied
EDIT: Thanks to @KonstantinSuvorov, I was able to more precisely pin down my issue – I seem to have attributed a module failure to the command's result of Permission Denied
because I got the best response using sudo
. See his post for why that was an issue.
Some Additional Information
On the server with Ansible installed, I have super user privileges. On the destination host I do not.
Normal SSHing into the destination host works perfectly fine and vice versa.
The following is what we see upon successfully logging in to any of our servers here at work, so don't be alarmed when it isn't familiar:
***************************************************************
* *
* Do not attempt to log on unless you are an authorized user. *
* *
* You must have a valid Network account. *
* *
***************************************************************
If it's necessary, I'll provide my ansible.cfg
when I get back to the office tomorrow.
Forgive me if this belongs in SuperUser, ServerFault, or somewhere else.
UPDATE
Running the command without sudo:
ansible all -a "/bin/pwd" -vvvv
Result:
Verbose Ansible Command Without Sudo
UPDATE 2
After placing ssh_args=
under [ssh_connection]
in my ansible.cfg
:
ansible all -a "pwd"
Result:
hostDestination | FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "\n***************************************************************\n* *\n* Do not attempt to log on unless you are an authorized user. *\n* *\n* You must have a valid Network account. *\n* *\n***************************************************************\n\nConnection to hostDestination closed.\r\n",
"module_stdout": " File \"/tmp/ansible_C2IrV6/ansible_module_command.py\", line 183\r\n out = b''\r\n ^\r\nSyntaxError: invalid syntax\r\n",
"msg": "MODULE FAILURE",
"rc": 0
}
NOTE: Running the command with Ansible's raw
module is successful:
ansible all -m raw -a "pwd"
Result:
hostDestination | SUCCESS | rc=0 >>
/home/user
***************************************************************
* *
* Do not attempt to log on unless you are an authorized user. *
* *
* You must have a valid Network account. *
* *
***************************************************************
Shared connection to hostDestination closed.
When I look at the verbose output (-vvvv
) of the regular command I see the following modules being used:
Using module_utils file /usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/module_utils/basic.py
Using module_utils file /usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/module_utils/_text.py
Using module_utils file /usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/module_utils/parsing/__init__.py
Using module_utils file /usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/module_utils/pycompat24.py
Using module_utils file /usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/module_utils/six/__init__.py
Using module file /usr/lib/python2.6/site-packages/ansible-2.4.0-py2.6.egg/ansible/modules/commands/command.py
I feel like one or more modules may be the issue seeing as the last line in the output above is similar to the following line in the failed command's output:
... /tmp/ansible_C2IrV6/ansible_module_command.py\ ...
It looks as if the Python interpreter is having an issue with the syntax of the empty binary string in this file. Unfortunantely, Ansible deletes the file immediately after running the command – preventing me from looking at line 183 to make my own assessment.