【小贴士】当无法使用Ansible发送ping时的应对方法

首先

我在 Mac 上使用 brew 安装了 Ansible(正在学习 Ansible)。然后,由于在执行 ping 时遇到了一些困难,所以我想分享一下解决方法。

事件

当对一个目标执行ping命令时,会显示如下错误。

% ansible -i 192.168.56.51 all -m ping --connection=local 
[WARNING]: Unable to parse /Users/satton/etc/ansible/192.168.56.51 as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'
% 

应对措施

在IP地址后面加上逗号。

%  ansible -i 192.168.56.51, all -m ping --connection=local
[WARNING]: Platform darwin on host 192.168.56.51 is using the discovered Python interpreter at
/usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
information.
192.168.56.51 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
% 

※也可执行ping命令来对多个主机进行诊断

% ansible -i 192.168.56.51,8.8.8.8,8.8.4.4 all -m ping --connection=local
[WARNING]: Platform darwin on host 8.8.4.4 is using the discovered Python interpreter at
/usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
information.
8.8.4.4 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[WARNING]: Platform darwin on host 192.168.56.51 is using the discovered Python interpreter at
/usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
information.
192.168.56.51 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[WARNING]: Platform darwin on host 8.8.8.8 is using the discovered Python interpreter at
/usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
information.
8.8.8.8 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
% 

请查阅

消除在执行Ansible时显示的警告,指定Python版本。

bannerAds