Ansible 为什么我不能应答我的测试服务器?

Ansible 为什么我不能应答我的测试服务器?,ansible,ping,Ansible,Ping,我试图运行Ansible Up和Running book中的示例 我的剧本目录 ls ansible.cfg hosts ubuntu-bionic-18.04-cloudimg-console.log Vagrantfile 主人 ansible.cfg [defaults] inventory = hosts remote_user = vagrant private_key_file = .vagrant/machines/default/virtualbox/private_ke

我试图运行Ansible Up和Running book中的示例

我的剧本目录

ls
ansible.cfg  hosts  ubuntu-bionic-18.04-cloudimg-console.log  Vagrantfile
主人

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。您还需要Python2(版本2.6或更高版本)或Python3(版本3.5或更高版本)

Ansible需要python出现在远程主机中

另外,关于
ping
模块的使用


尝试在远程主机中安装python(手动或使用
raw
module),然后重新运行脚本。

这只是因为您在终端中将ansible module和经典的ICMP ping命令混为一谈,而这两个命令并不等效。从上面的链接

这不是ICMP ping,这只是一个在远程节点上需要Python的简单测试模块

由于上述混乱,您无法解释运行playbook时收到的明确错误消息:

首先

与127.0.0.1的共享连接已关闭

。。。这意味着首先打开了连接,并且可以访问您的主机

第二

/bin/sh:1:/usr/bin/python:未找到


。。。这意味着python(ansible所需)未安装或不在默认路径中。

我也遇到了同样的错误。然后发现:

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

由于python安装在本地主机上,而python不安装在远程主机上,所以只在远程主机上安装了python。发现问题解决了

尝试在主机文件ansible\u python\u解释器=/usr/bin/python3中添加此内容
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",