---
- name: Ensure dependencies are installed
  apt:
    pkg: 'libnss3-tools'
    state: latest
- name: Download caddy and extract into /usr/bin
  unarchive:
    src: https://github.com/caddyserver/caddy/releases/download/v2.0.0-rc.3/caddy_2.0.0-rc.3_linux_amd64.tar.gz
    dest: /usr/bin/
    remote_src: yes
    creates: /usr/bin/caddy
- name: Ensure group "caddy" exists
  group:
    name: caddy
    system: yes
    state: present
- name: Create Caddy user
  user:
    name: "caddy"
    group: "caddy"
    system: true
    create_home: yes
    home: "/var/lib/caddy"
    shell: "/usr/sbin/nologin"
    comment: "Caddy web server"
- name: Writes the Caddy service file
  copy:
    src: caddy.service
    dest: /etc/systemd/system/caddy.service
    force: no
- name: Ensure caddy etc directory exists
  file:
    path: /etc/caddy
    state: directory
- name: Ensure Caddyfile is here
  file:
    path: /etc/caddy/Caddyfile
    state: touch
- name: Reread Systemd config
  systemd:
    daemon_reload: yes
- name: Start Caddy service
  systemd:
    name: caddy
    state: started
    enabled: yes

---
- name: Ensure dependencies are installed
  apt:
    pkg: 'libnss3-tools'
    state: latest
- name: Download caddy and extract into /usr/bin
  unarchive:
    src: https://github.com/caddyserver/caddy/releases/download/v2.1.1/caddy_2.1.1_linux_amd64.tar.gz
    dest: /usr/bin/
    remote_src: yes
- name: Ensure group "caddy" exists
  group:
    name: caddy
    system: yes
    state: present
- name: Create Caddy user
  user:
    name: "caddy"
    group: "caddy"
    system: true
    create_home: yes
    home: "/var/lib/caddy"
    shell: "/usr/sbin/nologin"
    comment: "Caddy web server"
- name: Writes the Caddy service file
  copy:
    src: caddy.service
    dest: /etc/systemd/system/caddy.service
    force: no
- name: Ensure caddy etc directory exists
  file:
    path: /etc/caddy
    state: directory
- name: Ensure Caddyfile is here
  file:
    path: /etc/caddy/Caddyfile
    state: touch
- name: Reread Systemd config
  systemd:
    daemon_reload: yes
- name: Start Caddy service
  systemd:
    name: caddy
    state: started
    enabled: yes

Update Caddy version, force creation of file
Update Caddy version, force creation of file
