ansible -m ping -u ubuntu us-west-2a
35.166.197.222 | FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Shared connection to 35.166.197.222 closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
"msg": "MODULE FAILURE"
}
Please use the issue template instead of deleting it- this is not an actionable or useful bug report. I suspect you're running Ubuntu 16+ or something else without a default python3 installed, but we can't tell that without a full bug report.
The latest images in AWS don't have a usable Python installed... you need to add this as a pre-task:
pre_tasks:
- name: Refresh apt cache
become: no
local_action: shell ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=5 {{ inventory_hostname }} sudo apt-get update
- name: Install Python-apt to pull in Python
become: no
local_action: shell ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ConnectTimeout=5 {{ inventory_hostname }} sudo apt-get install --no-install-recommends --assume-yes python-apt
I have to use this in my tasks to get the AMI to work nicely with Ansible.
Ubuntu Xenial has Python3 installed by default and I think it is located at /usr/bin/python3
(I am not very sure though).
See this answer: http://stackoverflow.com/questions/32429259/ansible-fails-with-bin-sh-1-usr-bin-python-not-found
Note that it is important to disable fact gathering for the initialization tasks.
Yeah, the python interpreter's path can be given on run time as
-e 'ansible_python_interpreter=/usr/local/bin/python' while running the script.
But there has to be some way in ansible configuration file where we can mention the python interpreter path OR is it there?
If not there, then it needs to be implemented.
Just use ansible_python_interpreter=/usr/bin/python3
in ur inventory file
@guruprasad85 This issue is waiting for your response. Please respond or the issue will be closed.
@guruprasad85 Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.
Here are the items we could not find in your description:
Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md
Since I needed python2, I added as first task:
- name: dependency provisioning
hosts: all
become: yes
become_method: sudo
gather_facts: false
tasks:
- name: install python2
raw: sudo apt-get -y install python-simplejson
More infos here
@guruprasad85 This issue is waiting for your response. Please respond or the issue will be closed.
The above explanations are sufficient to resolving this issue.
Some additional reading:
http://docs.ansible.com/ansible/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine
If you have further questions please stop by IRC or the mailing list:
You can also disable the _Gathering Facts_, put this in your book
- hosts: anything
gather_facts: False
@bcoca @sivel are there any plans to revisit this ? It seems to me like Ansible should at least attempt to use /usr/bin/python3
(or /usr/bin/python2
as appropriate) if /usr/bin/python
is not available.
@SpamapS reported that official Ubuntu AMIs on AWS only ship with /usr/bin/python3
:
ubuntu@ip-172-16-178-247:~$ uname -a
Linux ip-172-16-178-247 4.4.0-1065-aws #75-Ubuntu SMP Fri Aug 10 11:14:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@ip-172-16-178-247:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
ubuntu@ip-172-16-178-247:~$ ls -al /usr/bin |grep python
lrwxrwxrwx 1 root root 26 May 18 2016 dh_pypy -> ../share/dh-python/dh_pypy
lrwxrwxrwx 1 root root 29 May 18 2016 dh_python3 -> ../share/dh-python/dh_python3
lrwxrwxrwx 1 root root 23 Nov 28 2017 pdb3.5 -> ../lib/python3.5/pdb.py
lrwxrwxrwx 1 root root 31 Mar 23 2016 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx 1 root root 26 May 18 2016 pybuild -> ../share/dh-python/pybuild
lrwxrwxrwx 1 root root 9 Mar 23 2016 python3 -> python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 2017 python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 2017 python3.5m
-rwxr-xr-x 1 root root 976 Nov 27 2015 python3-jsondiff
-rwxr-xr-x 1 root root 3662 Nov 27 2015 python3-jsonpatch
-rwxr-xr-x 1 root root 1342 Oct 24 2015 python3-jsonpointer
lrwxrwxrwx 1 root root 10 Mar 23 2016 python3m -> python3.5m
For posterity, this is a known improvement opportunity for Ansible and is being considered for inclusion in the roadmap for >=2.8
In my case(ansible 2.7.0):
myIp | FAILED! => {
"changed": false,
"module_stderr": "",
"module_stdout": "/bin/sh: /usr/bin/python: No such file or directory\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 127
}
$ll |grep python
lrwxrwxrwx 1 root root 32 Jun 5 15:44 kylinpy -> /usr/local/python2.7/bin/kylinpy
lrwxrwxrwx 1 root root 34 Nov 16 2016 python -> /usr/local/python2.7/bin/python2.7
lrwxrwxrwx 1 root root 6 Sep 8 2016 python2 -> python
-rwxr-xr-x 1 root root 4864 May 29 2014 python2.6
-rwxr-xr-x 1 root root 1418 May 29 2014 python2.6-config
why softlink don't work either?
In my case(ansible 2.7.0):
myIp | FAILED! => {
"changed": false,
"module_stderr": "",
"module_stdout": "/bin/sh: /usr/bin/python: No such file or directory\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 127
}$ll |grep python
lrwxrwxrwx 1 root root 32 Jun 5 15:44 kylinpy -> /usr/local/python2.7/bin/kylinpy
lrwxrwxrwx 1 root root 34 Nov 16 2016 python -> /usr/local/python2.7/bin/python2.7
lrwxrwxrwx 1 root root 6 Sep 8 2016 python2 -> python
-rwxr-xr-x 1 root root 4864 May 29 2014 python2.6
-rwxr-xr-x 1 root root 1418 May 29 2014 python2.6-configwhy softlink don't work either?
sorry,it my fault.Use softlink,it works
a simple : ln -s /usr/bin/python3 /usr/bin/python resolved my issue
Just use
ansible_python_interpreter=/usr/bin/python3
in ur inventory file
Thanks, it works now
This seems to have issues with pyenv pyenv global <version>
.
It should shim it, but I'm guessing that Ansible is hard coded to look at /usr/bin/python
, as opposed to just using the python
command?
If so, is this ever likely to change? Or is there a workaround I can use?
If so, is this ever likely to change?
No, it is not.
You would need to explicitly set ansible_python_interpreter
to a python interpreter if you want to use something other than /usr/bin/python
.
Which in the case of pyenv
would likely just be the path to the shim (which python3.6
) or to the real binary (pyenv which python3.6
). Note, in many circumstances, you need to hard code that and cannot use shell expansion.
Most helpful comment
Just use
ansible_python_interpreter=/usr/bin/python3
in ur inventory file