Redid the ansible playbook
This commit is contained in:
@ -3,7 +3,7 @@ HOST=0.0.0.0
|
||||
PORT=80
|
||||
LOG_LEVEL=WARN
|
||||
DEBUG=false
|
||||
SQLALCHEMY_DATABASE_URI=postgresql+psycopg://postgres:123456@{{ db }}:5432/brewman_{{ name }}
|
||||
SQLALCHEMY_DATABASE_URI=postgresql+psycopg://postgres:123456@{{ db }}:5432/brewman_{{ instance }}
|
||||
MODULE_NAME=brewman.main
|
||||
PROJECT_NAME=brewman
|
||||
PUBLIC_KEY={{ public_key }}
|
||||
|
||||
@ -6,7 +6,15 @@
|
||||
become: true
|
||||
vars_files:
|
||||
- vars/default.yml
|
||||
- "{{ var_file }}"
|
||||
|
||||
pre_tasks:
|
||||
- name: Load per-host vars file from inventory (var_file)
|
||||
ansible.builtin.include_vars:
|
||||
file: "{{ var_file }}"
|
||||
when: var_file is defined
|
||||
|
||||
|
||||
roles:
|
||||
- network
|
||||
- brewman
|
||||
- caddy
|
||||
@ -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 }}"
|
||||
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
|
||||
# }
|
||||
5
ansible/roles/caddy/handlers/main.yaml
Normal file
5
ansible/roles/caddy/handlers/main.yaml
Normal 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"
|
||||
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('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
|
||||
9
ansible/roles/network/tasks/main.yaml
Normal file
9
ansible/roles/network/tasks/main.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: Ensure 'brewman' Docker network exists
|
||||
docker_network:
|
||||
name: "brewman_{{ instance }}_net"
|
||||
state: present
|
||||
connected:
|
||||
- "{{ db }}"
|
||||
- "{{ proxy }}"
|
||||
appends: yes
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
name: acc
|
||||
instance: acc
|
||||
title: "The Great Bear"
|
||||
|
||||
public_key: -----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAB+3c94GO2p6+cCOfaA1J0oQVbmZQieYaOqNbgHR70JM=\n-----END PUBLIC KEY-----
|
||||
@ -7,6 +7,6 @@ private_key: -----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEICdULYmhJhsQJPoCSc
|
||||
middleware_key: cb71666b9c
|
||||
|
||||
host: acc.hopsngrains.com
|
||||
host_directory: "brewman-{{ name }}"
|
||||
db_name: "brewman_{{ name }}"
|
||||
host_directory: "brewman-{{ instance }}"
|
||||
db_name: "brewman_{{ instance }}"
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
name: exp
|
||||
instance: exp
|
||||
title: Tanshu
|
||||
|
||||
public_key: -----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEABj/Hq4mOHC8fwTL+MJOr7HDFU+LmGfmQFOt90a+ZGtg=\n-----END PUBLIC KEY-----
|
||||
@ -7,5 +7,5 @@ private_key: -----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIGyEz6qjXMPtjWaYpa
|
||||
middleware_key: da6fcd999b
|
||||
|
||||
host: exp.tanshu.com
|
||||
host_directory: "brewman-{{ name }}"
|
||||
db_name: "brewman_{{ name }}"
|
||||
host_directory: "brewman-{{ instance }}"
|
||||
db_name: "brewman_{{ instance }}"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
name: hinchco
|
||||
instance: hinchco
|
||||
title: Mozimo
|
||||
|
||||
public_key: -----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAQUHP86TdF2/HRgpSOATueKxP16KONO+iTef1nITnlwc=\n-----END PUBLIC KEY-----
|
||||
@ -7,5 +7,5 @@ private_key: -----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIPWikH3em6asm4WVSO
|
||||
middleware_key: 1e36e7f678
|
||||
|
||||
host: acc.hinchco.in
|
||||
host_directory: "brewman-{{ name }}"
|
||||
db_name: "brewman_{{ name }}"
|
||||
host_directory: "brewman-{{ instance }}"
|
||||
db_name: "brewman_{{ instance }}"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
name: hops
|
||||
instance: hops
|
||||
title: "HnG Panchkula"
|
||||
|
||||
|
||||
@ -8,5 +8,5 @@ private_key: -----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIBEjfprZzihARk6Kgz
|
||||
middleware_key: 9c2bdd24be
|
||||
|
||||
host: hops.hopsngrains.com
|
||||
host_directory: "brewman-{{ name }}"
|
||||
db_name: "brewman_{{ name }}"
|
||||
host_directory: "brewman-{{ instance }}"
|
||||
db_name: "brewman_{{ instance }}"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
name: mhl
|
||||
instance: mhl
|
||||
title: "HnG Mohali"
|
||||
|
||||
public_key: -----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAerD1T7kXn4cDp8dw1xQapPMyrlq7WHq0PpnIWqzTq8c=\n-----END PUBLIC KEY-----
|
||||
@ -7,5 +7,5 @@ private_key: -----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIFguJkIzoUkxHSxvFW
|
||||
middleware_key: 9183bdcfb0
|
||||
|
||||
host: mhl.hopsngrains.com
|
||||
host_directory: "brewman-{{ name }}"
|
||||
db_name: "brewman_{{ name }}"
|
||||
host_directory: "brewman-{{ instance }}"
|
||||
db_name: "brewman_{{ instance }}"
|
||||
|
||||
Reference in New Issue
Block a user