- name: Add Caddy repository and key
  ansible.builtin.deb822_repository:
    name: 'caddy'
    types: 
      - deb
      - deb-src
    uris: 'https://dl.cloudsmith.io/public/caddy/stable/deb/debian'
    suites: 'any-version'
    components: 'main'
    signed_by: 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key'

- name: Install Caddy
  apt:
    name: caddy
    state: present

- name: Copy over Caddyfile
  copy:
    src: Caddyfile
    dest: '/etc/caddy/Caddyfile'
    owner: root
    group: root
    mode: '644'
  notify: 'reload caddy'

- name: Ensure Caddy service is running & enabled
  service:
    name: caddy
    state: started
    enabled: true

- name: Open HTTP ports in firewall
  community.general.ufw:
    port: '{{ item }}'
    rule: 'allow'
  loop:
    - 'http'
    - 'https'
