Add functionality by copy-pasting pre-generated certs to vm and update README.md

This commit includes the pre-generated certs in the files/certs
directory. README.md was thoroughly updated to include an example of
using certbot with this role and how to import the root.crt to Firefox.
This commit is contained in:
Santeri Kainulainen 2025-12-01 15:51:30 +02:00
parent b3204eb4da
commit 733c3ed250
8 changed files with 130 additions and 12 deletions

View file

@ -4,6 +4,7 @@
state: present
- name: Create Caddy configuration directory
become: yes
ansible.builtin.file:
path: /etc/caddy
state: directory
@ -12,15 +13,40 @@
mode: '0755'
- name: Deploy Caddyfile
become: yes
ansible.builtin.template:
src: Caddyfile.j2
dest: "{{ caddy_config_path }}"
owner: root
group: root
mode: '0644'
notify: Restart Caddy
- name: Ensure Caddy authorities directory exists
become: yes
ansible.builtin.file:
path: /var/lib/caddy/.local/share/caddy/pki/authorities/local
state: directory
owner: caddy
group: caddy
mode: '0700'
# Copy the pre-generated certs from files/certs folder to Caddy,
# so that you only need to import the root.crt once for all .local domains
- name: Deploy Caddy root certificates
become: yes
vars:
cert_list: "{{ lookup('fileglob', role_path + '/files/certs/*', wantlist=True) | map('basename') | list }}"
ansible.builtin.copy:
src: "certs/{{ item }}"
dest: "{{ caddy_authorities_path }}/{{ item }}"
owner: caddy
group: caddy
mode: '0600'
force: yes
loop: "{{ cert_list }}"
- name: Ensure Caddy root directory exists
become: yes
ansible.builtin.file:
path: "{{ caddy_root }}"
state: directory
@ -29,14 +55,24 @@
mode: '0755'
- name: Start and enable Caddy service
become: yes
ansible.builtin.service:
name: "{{ caddy_service_name }}"
state: started
enabled: true
- name: Restart Caddy
become: yes
ansible.builtin.service:
name: "{{ caddy_service_name }}"
state: restarted
# By default don't trust as its not usually needed
- name: Trust Caddy local CA
become: yes
copy:
src: /var/lib/caddy/.local/share/caddy/pki/authorities/local/root.crt
dest: /usr/local/share/ca-certificates/caddy-local.crt
remote_src: yes
notify: Update CA trust
notify: Update CA trust
when: caddy_trust_local_ca | default(false) | bool