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
By default, Ansible requires Python 2, however, Ansible 2.2+ can work with Python 3 as well.
So either install Python 2 using the
raw
module, e.g.or set
ansible_python_interpreter
variable in the inventory file, like:For Docker, you can add the following line:
or run it as:
As others said, this is due to missing python2. Other answers here provide a workaround with
pre_tasks
andgather_facts: no
, however if you're on EC2 and you spin up the instance with ansible you can useuser_data
option:Then people usually wait for ssh to be available like this:
However I've found, that this isn't always long enough as CloudInit is executed quite late in the boot process so the python2 still might not be installed right after ssh is available. So I've added a pause in case the instance was just created:
This will do the job perfectly and as an advantage you're not checking for python2 on every run and you don't have to do any workarounds to gather facts later.
I'm sure other cloud providers provide similar CloudInit functionality, so adapt for your use case.
According to this Gist you can install Python2 on Ubuntu 16.04 as follows:
I found out that it's actually possible to have multiple plays in a single playbook, so my setup now contains a "dependency provisioning" play which runs on all hosts, and other plays for specific hosts. So no more
pre_tasks
.For example:
To summarize everyone else's answers, here are the combined settings that worked for me:
You need python 2.7 to run Ansible. On Ubuntu 16.04, you can install it via this command:
sudo apt-get install python-minimal
After that, I could run
ansible-playbook -i inventories/staging playbook.yml
Please check more at Using ansible on Ubuntu 16.04