Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module_stdout: "/bin/sh: 1: /usr/bin/python: not found\r\n", #19605

Closed
guruprasad85 opened this issue Dec 21, 2016 · 19 comments
Closed

module_stdout: "/bin/sh: 1: /usr/bin/python: not found\r\n", #19605

guruprasad85 opened this issue Dec 21, 2016 · 19 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly.

Comments

@guruprasad85
Copy link

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"
}

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 needs_triage Needs a first human triage before being processed. labels Dec 21, 2016
@nitzmahone nitzmahone added needs_info This issue requires further information. Please answer any outstanding questions. and removed needs_triage Needs a first human triage before being processed. labels Dec 22, 2016
@nitzmahone
Copy link
Member

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.

@richard-scott
Copy link

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.

@georgepsarakis
Copy link

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.

@ashishsingh2k8
Copy link

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.

@Snelius30
Copy link

Just use ansible_python_interpreter=/usr/bin/python3 in ur inventory file

@ansibot
Copy link
Contributor

ansibot commented Mar 21, 2017

@guruprasad85 This issue is waiting for your response. Please respond or the issue will be closed.

click here for bot help

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Mar 21, 2017
@ansibot
Copy link
Contributor

ansibot commented Apr 11, 2017

@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:

  • issue type
  • ansible version
  • component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@ansibot ansibot added needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Apr 11, 2017
@Minipada
Copy link

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

@ansibot
Copy link
Contributor

ansibot commented May 11, 2017

@guruprasad85 This issue is waiting for your response. Please respond or the issue will be closed.

click here for bot help

@sivel
Copy link
Member

sivel commented May 11, 2017

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:

@juanarbol
Copy link

juanarbol commented Aug 22, 2017

You can also disable the Gathering Facts, put this in your book

- hosts: anything
  gather_facts: False

@dmsimard
Copy link
Contributor

dmsimard commented Aug 30, 2018

@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

@dmsimard
Copy link
Contributor

For posterity, this is a known improvement opportunity for Ansible and is being considered for inclusion in the roadmap for >=2.8

@yiding17
Copy link

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?

@yiding17
Copy link

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?

sorry,it my fault.Use softlink,it works

@Soufianux
Copy link

a simple : ln -s /usr/bin/python3 /usr/bin/python resolved my issue

@ghost
Copy link

ghost commented Jan 14, 2019

Just use ansible_python_interpreter=/usr/bin/python3 in ur inventory file

Thanks, it works now

@flatline-studios
Copy link
Contributor

flatline-studios commented Jan 15, 2019

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?

@sivel
Copy link
Member

sivel commented Jan 15, 2019

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.

@ansible ansible locked and limited conversation to collaborators Jan 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly.
Projects
None yet
Development

No branches or pull requests