在 ansible playbook 中 Ping 主机

Vee*_*dra 6 ping ansible

我只想 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
Run Code Online (Sandbox Code Playgroud)

但,

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"
}

Run Code Online (Sandbox Code Playgroud)

ping模块

---
- name: Set User
  hosts: dns
  gather_facts: false
  become: false

  tasks:
  - name: Pinging Host
    action: ping
Run Code Online (Sandbox Code Playgroud)

看起来它正在尝试 ssh 进入 IP。(在详细模式下检查)。我不知道为什么?如何进行 ICMP ping?我也不想将 DNS IP 放入库存中。

更新1:

嗯,看起来不支持linuxin ansible_network_os

https://www.reddit.com/r/ansible/comments/9dn5ff/possible_values_for_ansible_network_os/

iti*_*iic 7

您可以使用 ping 命令:

---

- hosts: all
  gather_facts: False
  connection: local

  tasks:

    - name: ping
      shell: ping -c 1 -w 2 8.8.8.8
      ignore_errors: true
Run Code Online (Sandbox Code Playgroud)


小智 5

尝试使用delegate_to模块指定此任务应在本地主机上执行。也许 ansible 正在尝试连接到这些设备来执行 ping shell 命令。以下代码示例对我有用。

tasks:
- name: ping test
  shell: ping -c 1 -w 2 {{ ansible_host }}
  delegate_to: localhost
  ignore_errors: true
Run Code Online (Sandbox Code Playgroud)