インフラ系SEの技術メモ

雑なエンジニアが低信頼性のメモを書いています。参考程度にとどめてください。

(Ansible)全ホストにpingを打つ

一斉Ping

以下で行えます。

$ ansible all -m ping

標準出力はこんな感じ。

serverb.lab.example.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
servera.lab.example.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

これはpingというパイソンモジュールを使っていますが、もし任意のコマンドを打ちたければcommandとかいて引数に入れる感じ。

$ ansible all -m command -a hostname
serverb.lab.example.com | CHANGED | rc=0 >>
serverb.lab.example.com
servera.lab.example.com | CHANGED | rc=0 >>
servera.lab.example.com

尚、pingの中身というかドキュメントは下記で確認できます。

$ ansible-doc ping
> PING    (/usr/lib/python3.6/site-packages/ansible/modules/system/ping.py)

        A trivial test module, this module always returns `pong' on
        successful contact. It does not make sense in playbooks, but
        it is useful from `/usr/bin/ansible' to verify the ability to
        login and that a usable Python is configured. This is NOT ICMP
        ping, this is just a trivial test module that requires Python
        on the remote-node. For Windows targets, use the [win_ping]
        module instead. For Network targets, use the [net_ping] module
        instead.

  * This module is maintained by The Ansible Core Team
OPTIONS (= is mandatory):
...

ピンポンってなんだか滑稽ですね。