Redid the ansible playbook

This commit is contained in:
2026-05-05 10:04:35 +00:00
parent d14aba1202
commit 7aeb2a6055
13 changed files with 76 additions and 36 deletions

View File

@ -23,16 +23,6 @@
src: "files/.env"
dest: "/var/lib/{{ host_directory }}/.env"
- name: Upload the Caddyfile template
template:
src: "files/Caddyfile"
dest: "/var/lib/{{ host_directory }}/Caddyfile"
- name: Create Docker network for Brewman
docker_network:
name: "brewman_{{ name }}_net"
state: present
- name: Create brewman container
docker_container:
name: "{{ host_directory }}"
@ -40,13 +30,8 @@
state: started
restart_policy: "unless-stopped"
env_file: "/var/lib/{{ host_directory }}/.env"
volumes:
- "/var/lib/{{ host_directory }}/frontend:/frontend"
networks:
- name: "brewman_{{ instance }}_net"
# volumes:
# - "/var/lib/{{ host_directory }}/frontend:/frontend"
- name: Connect DB container to Brewman network
docker_network:
name: "brewman_{{ name }}_net"
connected:
- "{{ db }}"
- "{{ proxy }}"
- "{{ host_directory }}"

View File

@ -0,0 +1,7 @@
caddy_container: caddy
caddyfile_path: /var/lib/caddy/conf/Caddyfile
# snippet_block: |
# {{ host }} {
# reverse_proxy {{ barker_container }}:80
# }

View File

@ -0,0 +1,5 @@
---
# Handlers for Caddy role
- name: Reload Caddy configuration
ansible.builtin.command: "docker exec -w /etc/caddy {{ caddy_container }} caddy reload"
listen: "Reload Caddy"

View File

@ -0,0 +1,26 @@
---
- name: Read snippet from template file
set_fact:
snippet_block: "{{ lookup('template', 'files/Caddyfile.j2') }}"
- name: Read current Caddyfile
ansible.builtin.slurp:
path: "{{ caddyfile_path }}"
register: caddyfile_raw
- name: Decode Caddyfile content
set_fact:
caddyfile_content: "{{ caddyfile_raw['content'] | b64decode }}"
- name: Check if snippet already exists
set_fact:
snippet_present: "{{ snippet_block in caddyfile_content }}"
- name: Add snippet if missing
ansible.builtin.blockinfile:
path: "{{ caddyfile_path }}"
marker: "# {mark} Ansible managed Caddy snippet for {{ host }}"
block: "{{ snippet_block }}"
create: yes
when: not snippet_present
notify: Reload Caddy configuration

View File

@ -0,0 +1,9 @@
---
- name: Ensure 'brewman' Docker network exists
docker_network:
name: "brewman_{{ instance }}_net"
state: present
connected:
- "{{ db }}"
- "{{ proxy }}"
appends: yes