ansible - 为什么我无法 Ansible ping 我的测试服务器?
问题描述
我正在尝试从 Ansible Up and Running 书中运行示例。
我的剧本目录
ls
ansible.cfg hosts ubuntu-bionic-18.04-cloudimg-console.log Vagrantfile
主机
testserver ansible_host=127.0.0.1 ansible_port=2222
ansible.cfg
[defaults]
inventory = hosts
remote_user = vagrant
private_key_file = .vagrant/machines/default/virtualbox/private_key
host_key_checking = False
流浪文件
config.vm.box = "ubuntu/bionic64"
当我尝试 ping
ansible testserver -m ping
我有
testserver | FAILED! => {
"changed": false,
"module_stderr": "Shared connection to 127.0.0.1 closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
"msg": "MODULE FAILURE",
"rc": 127
}
我可以 ssh 没有任何问题
ssh vagrant@127.0.0.1 -p 2222 -i /home/miki/playbooks/.vagrant/machines/default/virtualbox/private_key
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-50-generic x86_64)
System information as of Tue May 21 06:39:46 UTC 2019
System load: 0.0 Processes: 108
Usage of /: 18.5% of 9.63GB Users logged in: 0
Memory usage: 17% IP address for enp0s3: 10.0.2.15
Swap usage: 0%
Last login: Tue May 21 06:32:13 2019 from 10.0.2.2
为什么 ansible ping 不起作用?
解决方案
从错误信息
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
似乎远程主机没有安装 python。
在受管节点上,您需要一种通信方式,通常是 ssh。默认情况下,这使用 sftp。如果这不可用,您可以切换到 ansible.cfg 中的 scp。您还需要 Python 2(2.6 或更高版本)或 Python 3(3.5 或更高版本)。
Ansible 需要 python 存在于远程主机中。
此外,关于ping
模块的使用,它与ping
shell命令不同。
尝试在远程主机中安装 python(手动或使用raw
模块),然后重新运行脚本。
推荐阅读
- python - 调用类方法时出现 NameError
- android - 我的 CollapsingToolbarLayout 折叠后不会改变颜色
- python - 如何将 Wireshark 处理的数据转发到 python?用什么样的方法?
- c# - 如何将“Mech”的数据加入“Tech”数据?
- node.js - 使用 Node.js 加密文本文件中的各个行
- c++ - 查找指针数组的大小?
- ios - 尝试使用 ADMob 添加插页式广告时出错
- git - 使用 git-bash 将代码签入到 Azure DevOps 时出现致命错误
- ios - CoreVideo / IOSurface:未知像素格式
- c# - 如何使用 C++ 创建一个静态类来引用字符串变量?