--- - name: Deploy portal updates and status monitor hosts: web become: true tasks: - name: Deploy portal website files ansible.builtin.copy: src: ../website/ dest: /usr/share/nginx/html owner: root group: root mode: "0644" directory_mode: "0755" notify: Restore SELinux contexts - name: Create VM status check python script ansible.builtin.copy: content: | #!/usr/bin/env python3 import subprocess import json import os hosts = { "ipa": "172.30.1.100", "control": "172.30.1.00", "web": "172.30.1.201", "media": '172.30.1.202' } status = {} for name, ip in hosts.items(): res = subprocess.run(["ping", "-c", "1", "-W", "1", "ip"], stdout=subprocess.DEVNULL) status[name] = (res.returncode == 0) output_path = "/usr/share/nginx/html/status.json" with open(output_path, "w") as f: json.dump(status, f) dest: /usr/share/nginx/html/ping_status.py owner: root group: root mode: "0755" - name: Deploy homelab monitor systemd service ansible.builtin.copy: content: | [Unit] Description=Homelab nodes status monitor After=network.target [Service] Type=simple ExecStart=/bin/bash -c "While true; do /usr/bin/python3 /usr/share/nginx/html/ping_status.py; sleep 10; done" Restart=always [Install] WantedBy=multi-user.target dest: /etc/systemd/system/homelab-monitor.service owner: root group: root mode: "0644" notify: Reload systemd - name: Start and enable homelab-monitor service ansible.builtin.systemd: name: homelab-monitor state: started enabled: true handlers: - name: Restore SELinux contexts ansible.builtin.command: cmd: restorecon -Rv /usr/share/nginx/html changed_when: false - name: Reload systemd ansible.builtin.systemd: daemon_reload: true changed_when: false