infrastructure/playbooks/tasks/reload-caddy.yml

24 lines
936 B
YAML
Raw Normal View History

2024-10-07 21:58:56 +00:00
- name: Find existing caddy site configs
ansible.builtin.find:
paths: "{{ caddy_config_path }}"
recurse: false
2024-10-07 21:58:56 +00:00
register: find_result
- name: Map exisiting/wanted caddy site configs
ansible.builtin.set_fact:
caddy_site_configs_have: "{{ find_result.files | map(attribute='path') }}"
caddy_site_configs_want: "{{ all_services | my_service_attributes(inventory_hostname) | list_prefix_path_suffix(caddy_config_path, '.conf') }}"
- name: Remove unwanted caddy site configs
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ caddy_site_configs_have | difference(caddy_site_configs_want) }}"
become: true
- name: Reload caddy container
ansible.builtin.command:
cmd: docker compose exec app sh -c "caddy validate --config /etc/caddy/Caddyfile && caddy reload --config /etc/caddy/Caddyfile"
chdir: "{{ caddy_path }}"
when: "'local-dev' != inventory_hostname"
changed_when: true