Ansible fails with /bin/sh: 1: /usr/bin/python: no

2020-01-27 09:26发布

I'm running into an error I've never seen before. Here is the command and the error:

$ ansible-playbook create_api.yml

PLAY [straw] ******************************************************************

GATHERING FACTS ***************************************************************
failed: [104.55.47.224] => {"failed": true, "parsed": false}
/bin/sh: 1: /usr/bin/python: not found


TASK: [typical | install required system packages] *****************************
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ********************************************************************
           to retry, use: --limit @/Users/john/create_api.retry

104.55.47.224               : ok=0    changed=0    unreachable=0    failed=1

Here is the create_api.yml file:

---

- hosts: api
  remote_user: root
  roles:
    - api

And here is the hosts file:

[api]
104.55.47.224

I can remove the roles section and it won't make it to the first TASK, it will instead make it will only make it to the line /bin/sh: 1: /usr/bin/python: not found. What could be going on here?


NOTE: In case anyone is pinging the IP address and failing to get a response, you should know I've changed the IP address since pasting code.

EDIT python was installed locally, the problem was that it was not installed on the remote machine, which was running Ubuntu 15.04

19条回答
Melony?
2楼-- · 2020-01-27 09:46

I had the same issue, until I realised you also need to install python on the remote host as well as your own local machine. now it works!

查看更多
一夜七次
3楼-- · 2020-01-27 09:48

Lots of answers.. Thanks for posting as I got started from this page too!

I did a bit of digging and it was solid with Ubuntu 14.04LTS, Ubuntu 15.04LTS appeared to have dropped the latest python, and Ubuntu 16.04LTS appears to have dropped aptitude.

I put the following action in my bootstrap before doing any apt calls:

- name: "FIX: Ubuntu 16.04 LTS doesn't come with certain modules, required by ansible"
  raw: apt-get install python-minimal aptitude -y
  become: true
  become_user: root
  become_method: sudo

If you manage become elsewhere, feel free to strip it.

Sources:

查看更多
Deceive 欺骗
4楼-- · 2020-01-27 09:49

Ansible 2.2 features a tech preview of Python 3 support. To take advantage of this (so you don't have to install Python 2 on Ubuntu 16.04), just set the ansible_python_interpreter config option to /usr/bin/python3. This can be done on a per-host basis in your inventory file:

[db]
123.123.123.123 ansible_python_interpreter=/usr/bin/python3
查看更多
Bombasti
5楼-- · 2020-01-27 09:53

You can use the raw module to install Python on the remote hosts:

- raw: sudo apt-get install python-simplejson
查看更多
家丑人穷心不美
6楼-- · 2020-01-27 09:54

What I used to get this working on ubuntu 15.10 on a fresh Digital Ocean droplet:

# my-playbook.yml
- name: python2
  hosts: test
  gather_facts: no
  pre_tasks:
    - raw: sudo apt-get -y install python-simplejson

$ ansible-playbook path/to/my-playbook.yml

For ubuntu 16.04 on a fresh OVH SSD, I had to apt-get upgrade before the python2 packages were available.

查看更多
干净又极端
7楼-- · 2020-01-27 09:54

We just run into this.

We deploy ubuntu 16.04 on a vagrant so if you are not using vagrant my comment is pointless.

We installed the following vagrant plugins (trigger, shell-commander) and we get python 2.7.6 installed on the machine (which were not without thioose plugins) and after ansible can deploy

It was our last test, otherwise we were about to include this installation in a shell command in the Vagrant file

Hope it can help someone

查看更多
登录 后发表回答