1

I am trying to configure a server on AWS using ansible with a dynamic inventory script.

I created an ec2 instance which works fine and which I can manually ssh into. However, when trying to reach the instance (just to ping or to install software) I run into trouble.

ansible -i ec2.py all -m ping

xx.xx.xx.xx | FAILED! => {
"changed": false, 
"failed": true, 
"module_stderr": "Shared connection to xx.xx.xx.xx closed.\r\n", 
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 
"msg": "MODULE FAILURE", 
"rc": 0

}

and for

ansible-playbook deploy_site.yml -i ec2.py all

ERROR! the playbook: all could not be found

my all file lives in the directory group_vars

playbook
- deploy_site.yml
/group_vars
  -all

and looks like

ansible_user: ubuntu
ansible_ssh_private_key_file: ~/.ssh/key_pair.pem

my key_pair.pem file exists and with mod=600

All of this happens in a virtual environment specific ansible and both host and server are ubuntu 16.04.

Any thoughts on the reason for the connection problem?

techraf
  • 64,883
  • 27
  • 193
  • 198
Mike
  • 3,775
  • 8
  • 39
  • 79
  • Possible duplicate of [Ansible fails with /bin/sh: 1: /usr/bin/python: not found](http://stackoverflow.com/questions/32429259/ansible-fails-with-bin-sh-1-usr-bin-python-not-found) – techraf May 13 '17 at 03:05

2 Answers2

1

Please share the output of ls /usr/bin/python* and what is your ansible version.

Also try to install python and configure it on your group_vars:

apt-get install -y python-dev python3 python3-dev python3-setuptools

in your file try to do something like this:

ansible_user: ubuntu
ansible_ssh_private_key_file: ~/.ssh/key_pair.pem
ansible_python_interpreter=/usr/bin/python3

you can also try :

ansible -i ec2.py all -m ping -e 'ansible_python_interpreter=/usr/bin/python3'
Berlin
  • 1,456
  • 1
  • 21
  • 43
  • $ ls /usr/bin/python /usr/bin/python – Mike May 07 '17 at 18:04
  • which python /home/mike/.pyenv/shims/python – Mike May 07 '17 at 20:05
  • ansible 2.3.0.0 – Mike May 07 '17 at 20:10
  • @Mike did you tried to install the packages and follow my instructions ? also what is is the result of `ls /usr/bin/python*` ? to see all python versions on `/usr/bin` (you forgot the *) – Berlin May 07 '17 at 21:59
  • ls /usr/bin/python /usr/bin/python /usr/bin/python2-config /usr/bin/python3m /usr/bin/python2 /usr/bin/python3 /usr/bin/python-config /usr/bin/python2.7 /usr/bin/python3.5 /usr/bin/pythontex /usr/bin/python2.7-config /usr/bin/python3.5m /usr/bin/pythontex3 – Mike May 08 '17 at 09:15
  • so you have python on your local machine, can you check / install on the machine that you run the playbook and try again with my instruction, ansible_python_interpreter... – Berlin May 08 '17 at 09:32
  • I now use python3 and this works with your instructions! Ubuntu 16.04 only has python3 installed on the server. Hence the ansible_python_interpreter...=python3 instruction makes the difference! – Mike May 08 '17 at 13:40
1

The first problem:

/bin/sh: 1: /usr/bin/python: not found\r\n"

You must have Python installed on the target machine as well as on the control machine.


The second problem:

ansible-playbook deploy_site.yml -i ec2.py all

Remove all from the command.

With ansible-playbook you specify the target hosts inside the playbook with hosts directive.

techraf
  • 64,883
  • 27
  • 193
  • 198
  • ubuntu 16.04 does not have python2.7 installed anymore. Changing it to use the interpreter python3 did the trick for problem 1. Thanks for the pointer on problem 2! I mixed ansible and ansible-playbook commands. – Mike May 08 '17 at 13:41
  • Thats's exactly what I wrote: you need to install it. Mind that Python 3 support is experimental in Ansible and you might experience problems. – techraf May 08 '17 at 13:46