Ansible AWS dynamic inventory connection not working

拈花ヽ惹草 提交于 2020-01-24 20:48:07

问题


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?


回答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'



回答2:


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.



来源:https://stackoverflow.com/questions/43824773/ansible-aws-dynamic-inventory-connection-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!