Junior — Middle
How can you automate the verification of server resource availability using Ansible?
sobes.tech AI
Answer from AI
To automate the checking of server resource availability with Ansible, you can use the ping or wait_for modules.
- The
pingmodule checks if the host is reachable by Ansible (for example, if SSH responds). - The
wait_formodule allows you to verify the availability of a specific port or service on the server.
Example of using the ping module in a playbook:
- hosts: all
tasks:
- name: Check host availability
ansible.builtin.ping:
If the task succeeds, the server is accessible.
Example of checking port 80 availability with wait_for:
- hosts: all
tasks:
- name: Check port 80 availability
ansible.builtin.wait_for:
port: 80
timeout: 10
Thus, you can automate monitoring of server and service availability in an Ansible playbook.