role-caddy/tasks/main.yml
2022-12-11 00:36:54 +01:00

46 lines
1.1 KiB
YAML

---
- name: Gather variables for each operating system
include_vars: "{{ ansible_distribution | lower }}.yml"
- name: "Check caddy version"
ansible.builtin.shell: "set -eo pipefail; caddy version | cut -d' ' -f 1 | cut -d'v' -f 2"
args:
executable: /bin/bash
register: caddy_active_version
changed_when: false
failed_when: false
when: caddy_version_check|bool
- include_tasks: "create_user.yml"
- include_tasks: "install.yml"
- include_tasks: install_systemd.yml
when: ansible_service_mgr == "systemd"
- name: "Create config and data directory"
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ caddy_user }}"
group: "{{ caddy_group }}"
mode: '0755'
with_items:
- "/etc/caddy"
- name: "Configure caddy"
ansible.builtin.template:
src: Caddyfile.j2
dest: /etc/caddy/Caddyfile
owner: "{{ caddy_user }}"
group: "{{ caddy_group }}"
mode: 0600
notify: "Restart caddy"
- name: "Service caddy"
ansible.builtin.service:
name: caddy
state: started
enabled: true
when: ansible_service_mgr == "systemd"