- name: Create Caddy Proxy
  hosts: caddy
  tasks:
    - name: Copy Containerfile for build
      template:
        src: Containerfile
        dest: /etc/caddy/Containerfile
        owner: root
        group: root
        mode: "0644"
    - name: Build Caddy Image
      shell:
        cmd: podman build -t gitea.reeseapps.com/services/caddy:latest -f /etc/caddy/Containerfile
    - name: Create /etc/caddy dir
      ansible.builtin.file:
        path: /etc/caddy
        state: directory
        mode: "0755"
    - name: Copy Caddyfile
      template:
        src: secrets/proxy.Caddyfile
        dest: /etc/caddy/Caddyfile
        owner: root
        group: root
        mode: "0644"
    - name: Copy rules.json
      template:
        src: rules.json
        dest: /etc/caddy/rules.json
        owner: root
        group: root
        mode: "0644"
    - name: Template Caddy Container Services
      template:
        src: caddy.container
        dest: /etc/containers/systemd/caddy.container
        owner: root
        group: root
        mode: "0644"
    - name: Reload and start the Caddy service
      ansible.builtin.systemd_service:
        state: restarted
        name: caddy.service
        enabled: true
        daemon_reload: true
