简体   繁体   中英

Ansible AWS dynamic inventory connection not working

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?

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM