Improve ansible stuff and prepare caddy

This commit is contained in:
Tobias Reisinger 2023-06-26 01:17:41 +02:00
parent 2d8c670110
commit 3b9ed6a4f4
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
10 changed files with 83 additions and 42 deletions
_ansible/roles/caddy/tasks

View file

@ -0,0 +1,11 @@
- name: Find caddy site configs, but exclude managed sites
ansible.builtin.find:
paths: "{{ caddy_config_path }}"
excludes: "{{ managed_sites | default([]) }}"
register: files_to_delete
- name: Remove unmanaged sites
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"

View file

@ -0,0 +1,11 @@
---
- name: Deploy {{ svc.name }}
tags:
- caddy
- reverse_proxy
- webserver
block:
- import_tasks: deploy-common-service.yml
- import_tasks: clean-sites.yml
- import_tasks: reload-caddy.yml

View file

@ -0,0 +1,16 @@
- name: Check caddy configuration
ansible.builtin.command:
cmd: docker compose exec app sh -c "caddy validate --config /etc/caddy/Caddyfile"
chdir: "{{ service_path }}"
when: "'local-dev' != inventory_hostname"
register: cmd_result
changed_when: false
- name: Reload caddy configuration
ansible.builtin.command:
cmd: docker compose exec app sh -c "caddy reload --config /etc/caddy/Caddyfile"
chdir: "{{ service_path }}"
when:
- "'local-dev' != inventory_hostname"
- cmd_result.rc == 0
changed_when: true # TODO find a way to detect changes