【问题标题】:Ansible AWS dynamic inventory connection not workingAnsible AWS 动态清单连接不起作用
【发布时间】:2017-10-05 02:32:30
【问题描述】:

我正在尝试使用带有动态清单脚本的 ansible 在 AWS 上配置服务器。

我创建了一个运行良好的 ec2 实例,我可以手动 ssh 进入。但是,当尝试访问实例时(只是为了 ping 或安装软件)我遇到了麻烦。

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

}

对于

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

ERROR! the playbook: all could not be found

我的所有文件都在目录 group_vars 中

playbook
- deploy_site.yml
/group_vars
  -all

看起来像

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

我的 key_pair.pem 文件存在并且 mod=600

所有这些都发生在特定于虚拟环境的 ansible 中,主机和服务器都是 ubuntu 16.04。

对连接问题的原因有什么想法吗?

【问题讨论】:

标签: amazon-web-services amazon-ec2 ansible boto


【解决方案1】:

请分享ls /usr/bin/python* 的输出以及您的ansible 版本。

也尝试安装 python 并在你的group_vars 上配置它:

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

在您的文件中尝试执行以下操作:

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

你也可以试试:

ansible -i ec2.py all -m ping -e 'ansible_python_interpreter=/usr/bin/python3'

【讨论】:

  • $ ls /usr/bin/python /usr/bin/python
  • 哪个python /home/mike/.pyenv/shims/python
  • ansible 2.3.0.0
  • @Mike 您是否尝试安装这些软件包并按照我的说明进行操作? ls /usr/bin/python* 的结果是什么?在/usr/bin 上查看所有 python 版本(你忘记了 *)
  • 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
【解决方案2】:

第一个问题:

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

您必须在 target 机器以及控制机器上安装 Python。


第二个问题:

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

从命令中删除all

使用ansible-playbook,您可以使用hosts 指令在playbook 中指定目标主机。

【讨论】:

  • ubuntu 16.04 不再安装 python2.7。将其更改为使用解释器 python3 解决了问题 1。感谢问题 2 的指针!我混合了 ansible 和 ansible-playbook 命令。
  • 这正是我写的:你需要安装它。请注意,Python 3 支持在 Ansible 中是实验性的,您可能会遇到问题。
猜你喜欢
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
  • 2015-05-14
  • 2020-05-24
  • 1970-01-01
  • 1970-01-01
  • 2020-11-18
相关资源
最近更新 更多