# FOR loop — to check the httpd service is running or not
for server in web01 web02 web03; do
echo "Checking $server..."
ssh "$server" "systemctl status httpd"
done
ansible-playbook check_httpd_status.yml -i inventory.ini
name: Check HTTPD service status on multiple servers
hosts: webservers
become: yes
gather_facts: no
tasks:
name: Get HTTPD service status
ansible.builtin.systemd:
name: httpd
register: httpd_status
name: Display HTTPD status
ansible.builtin.debug:
msg: |
Host: {{ inventory_hostname }}
Service State: {{ httpd_status.status.ActiveState }}
Sub State: {{ httpd_status.status.SubState }}
No comments:
Post a Comment