Update for new deployment with Caddy and docker networks
This commit is contained in:
@ -30,10 +30,7 @@
|
||||
state: started
|
||||
restart_policy: "unless-stopped"
|
||||
env_file: "/var/lib/{{ host_directory }}/.env"
|
||||
links:
|
||||
- "postgres:db"
|
||||
- "redis:redis"
|
||||
published_ports:
|
||||
- "127.0.0.1:{{ host_port }}:80"
|
||||
volumes:
|
||||
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
||||
networks:
|
||||
- name: "{{ docker_network }}"
|
||||
# volumes:
|
||||
# - "/var/lib/{{ host_directory }}/frontend:/frontend"
|
||||
|
||||
7
ansible/roles/caddy/defaults/main.yaml
Normal file
7
ansible/roles/caddy/defaults/main.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
caddy_container: caddy
|
||||
caddyfile_path: /var/lib/caddy/conf/Caddyfile
|
||||
# snippet_block: |
|
||||
# {{ host }} {
|
||||
# reverse_proxy {{ barker_container }}:80
|
||||
# }
|
||||
7
ansible/roles/caddy/handlers/main.yaml
Normal file
7
ansible/roles/caddy/handlers/main.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
# Handlers for Nginx role
|
||||
- name: Restart caddy container
|
||||
docker_container:
|
||||
name: "{{ caddy_container }}"
|
||||
state: started
|
||||
restart: true
|
||||
26
ansible/roles/caddy/tasks/main.yaml
Normal file
26
ansible/roles/caddy/tasks/main.yaml
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
- name: Read snippet from template file
|
||||
set_fact:
|
||||
snippet_block: "{{ lookup('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: Restart caddy container
|
||||
11
ansible/roles/network/tasks/main.yaml
Normal file
11
ansible/roles/network/tasks/main.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
# Tasks for Mosquitto role
|
||||
- name: Ensure 'iot' Docker network exists
|
||||
docker_network:
|
||||
name: "{{ docker_network }}"
|
||||
state: present
|
||||
connected:
|
||||
- caddy
|
||||
- valkey
|
||||
- postgres
|
||||
appends: yes
|
||||
@ -1,2 +0,0 @@
|
||||
---
|
||||
# Default variables for Nginx role
|
||||
@ -1,6 +0,0 @@
|
||||
---
|
||||
# Handlers for Nginx role
|
||||
- name: Reload Nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
@ -1,24 +0,0 @@
|
||||
---
|
||||
# Tasks for Nginx role
|
||||
- name: Check if Nginx conf file exists
|
||||
stat:
|
||||
path: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
register: status
|
||||
|
||||
- name: No need to reload Nginx
|
||||
debug:
|
||||
msg: "No need to reload Nginx as sites-available entries have already been created"
|
||||
|
||||
- name: Set Nginx conf file
|
||||
when: status.stat.exists == false
|
||||
template:
|
||||
src: "files/nginx.conf.j2"
|
||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
|
||||
- name: Enable new site
|
||||
when: status.stat.exists == false
|
||||
file:
|
||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
||||
state: link
|
||||
notify: Reload Nginx
|
||||
Reference in New Issue
Block a user