在 ansible playbook 中 Ping 主机
Ping a host inside ansible playbook
我只想 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 放入清单中。
更新1:
嗯,看起来 ansible_network_os
中不支持 linux
。
https://www.reddit.com/r/ansible/comments/9dn5ff/possible_values_for_ansible_network_os/
您可以使用 ping 命令:
---
- hosts: all
gather_facts: False
connection: local
tasks:
- name: ping
shell: ping -c 1 -w 2 8.8.8.8
ignore_errors: true
尝试使用delegate_to 模块指定此任务应在本地主机上执行。也许 ansible 正在尝试连接到这些设备以执行 ping shell 命令。以下代码示例适用于我。
tasks:
- name: ping test
shell: ping -c 1 -w 2 {{ ansible_host }}
delegate_to: localhost
ignore_errors: true
也可以 run/check ping 延迟通过下面的 ansible adhoc 命令
ansible all -m shell -a "ping -c3 google.com"
我只想 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 放入清单中。
更新1:
嗯,看起来 ansible_network_os
中不支持 linux
。
https://www.reddit.com/r/ansible/comments/9dn5ff/possible_values_for_ansible_network_os/
您可以使用 ping 命令:
---
- hosts: all
gather_facts: False
connection: local
tasks:
- name: ping
shell: ping -c 1 -w 2 8.8.8.8
ignore_errors: true
尝试使用delegate_to 模块指定此任务应在本地主机上执行。也许 ansible 正在尝试连接到这些设备以执行 ping shell 命令。以下代码示例适用于我。
tasks:
- name: ping test
shell: ping -c 1 -w 2 {{ ansible_host }}
delegate_to: localhost
ignore_errors: true
也可以 run/check ping 延迟通过下面的 ansible adhoc 命令
ansible all -m shell -a "ping -c3 google.com"