Ansible Quick Start Guide
上QQ阅读APP看书,第一时间看更新

Ad hoc versus playbook: the ping module

As discussed previously, Ansible ad hoc can be used for a quick check, such as running a ping command to check if the hosts are up and running. The command should look as follows:

ansible servers -m ping

The output of the command will look similar to the following:

The ping module can also be used in the playbook as part of the bigger script, where the result of the ping can be piped to be the condition for another action. The playbook code is as follows:

---
- name: Ping module playbook usage
hosts: servers
gather_facts: false
tasks:
- name: ping the local servers
ping:

The output of this code will look as follows: