首页 > 解决方案 > 为什么我无法 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 不起作用?

标签: ansibleping

解决方案


从错误信息

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

似乎远程主机没有安装 python。

引用requiremet docs

在受管节点上,您需要一种通信方式,通常是 ssh。默认情况下,这使用 sftp。如果这不可用,您可以切换到 ansible.cfg 中的 scp。您还需要 Python 2(2.6 或更高版本)或 Python 3(3.5 或更高版本)。

Ansible 需要 python 存在于远程主机中。

此外,关于ping模块的使用,它与pingshell命令不同。

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


推荐阅读