我只想ping主机(DNS主机)以检查可达性。看起来没有适当的方法来做到这一点?我不确定。以下是我的net_ping
---
- name: Set User
hosts: web_servers
gather_facts: false
become: false
vars:
ansible_network_os: linux
tasks:
- name: Pinging Host
net_ping
dest: 10.250.30.11
但是
TASK [Pinging Host] *******************************************************************************************************************
task path: /home/veeru/PycharmProjects/Miscellaneous/tests/ping_test.yml:10
ok: [10.250.30.11] => {
"changed": false,
"msg": "Could not find implementation module net_ping for linux"
}
带有ping
模块
---
- name: Set User
hosts: dns
gather_facts: false
become: false
tasks:
- name: Pinging Host
action: ping
似乎正在尝试通过ssh进入IP。(在详细模式下检查)。不知道为什么如何进行ICMP ping?我也不想将DNS IP也放入清单中。
UPDATE1:
嗯,linux
中似乎不支持ansible_network_os
。
https://www.reddit.com/r/ansible/comments/9dn5ff/possible_values_for_ansible_network_os/
答案 0 :(得分:2)
尝试使用delegate_to模块来指定应在本地主机上执行此任务。也许ansible正在尝试连接到这些设备以执行ping shell命令。以下代码示例对我有用。
tasks:
- name: ping test
shell: ping -c 1 -w 2 {{ ansible_host }}
delegate_to: localhost
ignore_errors: true
答案 1 :(得分:0)
您可以使用ping命令:
---
- hosts: all
gather_facts: False
connection: local
tasks:
- name: ping
shell: ping -c 1 -w 2 8.8.8.8
ignore_errors: true