--- - name: Configure Servers hosts: all become: true tasks: - name: Ping host to verify connection ansible.builtin.ping: - name: Update apt cache and upgrade system packages ansible.builtin.apt: update_cache: true upgrade: dist cache_valid_time: 3600 - name: Check if a reboot is required. ansible.builtin.stat: path: /var/run/reboot-required get_checksum: no register: reboot_required_file - name: Reboot server and wait for it to finish when: reboot_required_file.stat.exists == true ansible.builtin.reboot: msg: "Rebooting post system update" connect_timeout: 5 reboot_timeout: 300 pre_reboot_delay: 0 post_reboot_delay: 15 test_command: uptime - name: Install prerequisites ansible.builtin.apt: pkg: - debian-keyring - debian-archive-keyring - apt-transport-https - curl state: present - name: Configure Caddy Server hosts: caddy become: true tags: - caddy handlers: - name: Restart Caddy service ansible.builtin.service: name: caddy state: restarted enabled: true tasks: - name: Add Caddy's official Repository ansible.builtin.deb822_repository: name: caddy uris: https://dl.cloudsmith.io/public/caddy/stable/deb/debian signed_by: https://dl.cloudsmith.io/public/caddy/stable/gpg.key suites: - any-version components: - main - name: Update apt cache to ensure we have the latest version of Caddy ansible.builtin.apt: update_cache: true - name: Install Caddy ansible.builtin.apt: pkg: - caddy state: present - name: Create Caddyfile from template notify: Restart Caddy service ansible.builtin.template: src: Caddyfile.j2 dest: /etc/caddy/Caddyfile mode: "0644" - name: Configure Monitoring Server hosts: monitoring become: true tags: - monitoring handlers: - name: Restart Prometheus service ansible.builtin.service: name: prometheus state: restarted enabled: true tasks: - name: Install Prometheus ansible.builtin.apt: pkg: - prometheus state: present - name: Configure Prometheus Alert Rules from template notify: Restart Prometheus service ansible.builtin.template: src: alert_rules.yml.j2 dest: /etc/prometheus/alert_rules.yml mode: "0644" - name: Configure Prometheus from template notify: Restart Prometheus service ansible.builtin.template: src: prometheus.yml.j2 dest: /etc/prometheus/prometheus.yml mode: "0644"