82 lines
2.0 KiB
YAML
82 lines
2.0 KiB
YAML
---
|
|
# file: roles/caddy/tasks/main.yml
|
|
#
|
|
# Configure Caddy.
|
|
|
|
- name: Check Caddy package signing key
|
|
ansible.builtin.stat:
|
|
path: /etc/apt/keyrings/caddy-stable-archive-keyring.key
|
|
register: caddy_signing_key_stat
|
|
tags:
|
|
- packages
|
|
- caddy
|
|
|
|
# See: https://caddyserver.com/docs/install#debian-ubuntu-raspbian
|
|
- name: Download Caddy package signing key
|
|
ansible.builtin.get_url:
|
|
url: https://dl.cloudsmith.io/public/caddy/stable/gpg.key
|
|
dest: /etc/apt/keyrings/caddy-stable-archive-keyring.key
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
register: download_caddy_signing_key
|
|
when: not caddy_signing_key_stat.stat.exists
|
|
tags:
|
|
- packages
|
|
- caddy
|
|
|
|
- name: Add Caddy stable repo
|
|
ansible.builtin.apt_repository:
|
|
repo: deb [signed-by=/etc/apt/keyrings/caddy-stable-archive-keyring.key] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main
|
|
filename: caddy-stable
|
|
state: present
|
|
register: add_caddy_apt_repository
|
|
tags:
|
|
- packages
|
|
- caddy
|
|
|
|
- name: Update apt cache
|
|
ansible.builtin.apt: # noqa no-handler
|
|
update_cache: true
|
|
when: (download_caddy_signing_key.status_code is defined and download_caddy_signing_key.status_code == 200) or add_caddy_apt_repository is changed
|
|
tags:
|
|
- packages
|
|
- caddy
|
|
|
|
- name: Install Caddy
|
|
ansible.builtin.apt:
|
|
name: caddy
|
|
state: present
|
|
install_recommends: false
|
|
cache_valid_time: 3600
|
|
tags:
|
|
- caddy
|
|
- packages
|
|
|
|
- name: Create Caddyfile
|
|
ansible.builtin.template:
|
|
src: etc/caddy/Caddyfile.j2
|
|
dest: /etc/caddy/Caddyfile
|
|
mode: "0755"
|
|
owner: root
|
|
group: root
|
|
notify:
|
|
- reload caddy
|
|
tags: caddy
|
|
|
|
- name: Create Caddy conf.d directory
|
|
ansible.builtin.file:
|
|
path: /etc/caddy/conf.d
|
|
state: directory
|
|
mode: "0755"
|
|
owner: root
|
|
group: root
|
|
|
|
# TODO: the variable is still named nginx_vhosts
|
|
- name: Configure Caddy virtual hosts
|
|
ansible.builtin.include_tasks: vhosts.yml
|
|
when: nginx_vhosts is defined
|
|
tags: caddy
|
|
|
|
# vim: set sw=2 ts=2:
|