refactor: move all service roles into a single alpina role
This commit is contained in:
parent
ec335e5d3c
commit
145c5db29f
5
.idea/alpina.iml
generated
5
.idea/alpina.iml
generated
@ -23,11 +23,6 @@
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
|
||||
<option name="TEMPLATE_FOLDERS">
|
||||
<list>
|
||||
<option value="$MODULE_DIR$/roles/traefik/templates" />
|
||||
<option value="$MODULE_DIR$/roles/gitea/templates" />
|
||||
<option value="$MODULE_DIR$/roles/nextcloud/templates" />
|
||||
<option value="$MODULE_DIR$/roles/arrstack/templates" />
|
||||
<option value="$MODULE_DIR$/roles/jellyfin/templates" />
|
||||
<option value="$MODULE_DIR$/roles/docker_host/templates" />
|
||||
</list>
|
||||
</option>
|
||||
|
@ -1,39 +0,0 @@
|
||||
# https://stackoverflow.com/questions/41667864/can-the-templates-module-handle-multiple-templates-directories
|
||||
|
||||
- name: Ensure service directory exists
|
||||
file:
|
||||
path: "{{ current_svc_path }}"
|
||||
state: directory
|
||||
mode: "700"
|
||||
|
||||
- name: Ensure directory structure exists
|
||||
file:
|
||||
path: "{{ current_svc_path }}/{{ item.path }}"
|
||||
state: directory
|
||||
mode: "700"
|
||||
with_community.general.filetree: "{{ templates_source }}"
|
||||
when: item.state == "directory"
|
||||
|
||||
|
||||
- name: Include app config variables
|
||||
include_vars:
|
||||
file: "{{ role_path }}/vars/app_config.yml"
|
||||
|
||||
- name: Generate {{ current_svc_name }} deployment from templates
|
||||
template:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ current_svc_path }}/{{ item.path | regex_replace('\\.j2$', '') }}"
|
||||
mode: "600"
|
||||
with_community.general.filetree: "{{ templates_source }}"
|
||||
when: item.state == "file"
|
||||
|
||||
- name: Deploy docker-compose for {{ current_svc_name }}
|
||||
command: docker compose -f "{{ current_svc_path }}/docker-compose.yml" up -d --pull --remove-orphans
|
||||
register: docker_compose_output
|
||||
# Not perfect idempotency, but the built-in docker_compose module doesn't support docker-compose v2
|
||||
# And of course there's an IPv6 bug in docker-compose v1, smh
|
||||
# https://github.com/docker/compose/issues/7670
|
||||
changed_when: "'created' in docker_compose_output.stderr.lower()"
|
||||
|
||||
- debug:
|
||||
var: docker_compose_output
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
my_svc_path: ~/services
|
||||
my_svc_path: ~/alpina
|
||||
base_volume_path: /mnt/dock
|
||||
media_volume_path: /mnt/media
|
||||
|
||||
|
18
roles/alpina/tasks/deploy_collection.yml
Normal file
18
roles/alpina/tasks/deploy_collection.yml
Normal file
@ -0,0 +1,18 @@
|
||||
- name: Ensure {{ collection }} collection directory exists
|
||||
file:
|
||||
path: "{{ my_svc_path }}/{{ collection }}"
|
||||
state: directory
|
||||
mode: "700"
|
||||
|
||||
- name: Deploy docker compose stacks for {{ collection }}
|
||||
vars:
|
||||
current_stack_name: "{{ stack }}"
|
||||
current_stack_dest: "{{ my_svc_path }}/{{ collection }}/{{ stack }}"
|
||||
current_stack_source: "{{ role_path }}/collections/{{ collection }}/{{ stack }}"
|
||||
include_tasks: deploy_compose_stack.yml
|
||||
loop: "{{ stacks }}"
|
||||
loop_control:
|
||||
loop_var: stack
|
||||
|
||||
- debug:
|
||||
var: acme_email
|
40
roles/alpina/tasks/deploy_compose_stack.yml
Normal file
40
roles/alpina/tasks/deploy_compose_stack.yml
Normal file
@ -0,0 +1,40 @@
|
||||
# https://stackoverflow.com/questions/41667864/can-the-templates-module-handle-multiple-templates-directories
|
||||
|
||||
- name: Ensure stack directory exists
|
||||
file:
|
||||
path: "{{ current_stack_dest }}"
|
||||
state: directory
|
||||
mode: "700"
|
||||
|
||||
- name: Ensure directory structure exists
|
||||
file:
|
||||
path: "{{ current_stack_dest }}/{{ item.path }}"
|
||||
state: directory
|
||||
mode: "700"
|
||||
with_community.general.filetree: "{{ current_stack_source }}/templates"
|
||||
when: item.state == "directory"
|
||||
|
||||
# TODO: This is not ideal as it leaks the variables between stacks
|
||||
# But that's also not really a problem, as they won't conflict if everything is done right
|
||||
- name: Include variables for stack {{ stack }}
|
||||
include_vars:
|
||||
file: "{{ current_stack_source }}/app_config.yml"
|
||||
|
||||
- name: Generate {{ current_stack_name }} deployment from templates
|
||||
template:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ current_stack_dest }}/{{ item.path | regex_replace('\\.j2$', '') }}"
|
||||
mode: "600"
|
||||
with_community.general.filetree: "{{ current_stack_source }}/templates"
|
||||
when: item.state == "file"
|
||||
|
||||
- name: Deploy docker-compose for {{ current_stack_name }}
|
||||
command: docker compose -f "{{ current_stack_dest }}/docker-compose.yml" up -d --pull --remove-orphans
|
||||
register: docker_compose_output
|
||||
# Not perfect idempotency, but the built-in docker_compose module doesn't support docker-compose v2
|
||||
# And of course there's an IPv6 bug in docker-compose v1, smh
|
||||
# https://github.com/docker/compose/issues/7670
|
||||
changed_when: "'created' in docker_compose_output.stderr.lower()"
|
||||
|
||||
- debug:
|
||||
var: docker_compose_output
|
23
roles/alpina/tasks/main.yml
Normal file
23
roles/alpina/tasks/main.yml
Normal file
@ -0,0 +1,23 @@
|
||||
- name: Ensure alpina directory exists
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ my_svc_path }}"
|
||||
mode: "700"
|
||||
|
||||
- name: Deploy collection services
|
||||
vars:
|
||||
collection: services
|
||||
stacks:
|
||||
- traefik
|
||||
- authentik
|
||||
import_tasks: deploy_collection.yml
|
||||
|
||||
- name: Deploy collection apps
|
||||
vars:
|
||||
collection: apps
|
||||
stacks:
|
||||
- gitea
|
||||
- nextcloud
|
||||
- jellyfin
|
||||
- arrstack
|
||||
import_tasks: deploy_collection.yml
|
@ -1,2 +0,0 @@
|
||||
- name: "Docker compose steps for {{ current_svc_name }}"
|
||||
import_tasks: "{{ playbook_dir }}/contrib/docker_compose_template_task_list.yml"
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
current_svc_name: arrstack
|
||||
current_svc_path: "{{ my_svc_path }}/{{ current_svc_name }}"
|
||||
|
||||
templates_source: "{{ role_path }}/templates"
|
@ -1,2 +0,0 @@
|
||||
- name: "Docker compose steps for {{ current_svc_name }}"
|
||||
import_tasks: "{{ playbook_dir }}/contrib/docker_compose_template_task_list.yml"
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
current_svc_name: authentik
|
||||
current_svc_path: "{{ my_svc_path }}/{{ current_svc_name }}"
|
||||
|
||||
templates_source: "{{ role_path }}/templates"
|
@ -1,9 +1,3 @@
|
||||
- name: Create my service directory
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ my_svc_path }}"
|
||||
mode: "700"
|
||||
|
||||
- name: Get IPv6 subnet for Docker
|
||||
set_fact:
|
||||
docker_ipv6_subnet: "{{ \
|
||||
@ -35,6 +29,27 @@
|
||||
state: disabled
|
||||
register: docker0_firewalld
|
||||
|
||||
- name: Get list of running Docker containers
|
||||
docker_host_info:
|
||||
containers: yes
|
||||
register: docker_container_list
|
||||
when: clean_desired is true
|
||||
|
||||
- name: Stop all running Docker containers
|
||||
docker_container:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
loop: "{{ docker_container_list.containers | map(attribute='Id') | list }}"
|
||||
async: 300
|
||||
poll: 0
|
||||
when: clean_desired is true and docker_container_list.containers | length > 0
|
||||
|
||||
- name: Prune all Docker containers and networks
|
||||
docker_prune:
|
||||
containers: yes
|
||||
networks: yes
|
||||
when: clean_desired is true
|
||||
|
||||
- name: Restart Docker daemon
|
||||
become: yes
|
||||
service:
|
||||
|
@ -1,2 +0,0 @@
|
||||
- name: "Docker compose steps for {{ current_svc_name }}"
|
||||
import_tasks: "{{ playbook_dir }}/contrib/docker_compose_template_task_list.yml"
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
current_svc_name: gitea
|
||||
current_svc_path: "{{ my_svc_path }}/{{ current_svc_name }}"
|
||||
|
||||
templates_source: "{{ role_path }}/templates"
|
@ -1,2 +0,0 @@
|
||||
- name: "Docker compose steps for {{ current_svc_name }}"
|
||||
import_tasks: "{{ playbook_dir }}/contrib/docker_compose_template_task_list.yml"
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
current_svc_name: jellyfin
|
||||
current_svc_path: "{{ my_svc_path }}/{{ current_svc_name }}"
|
||||
|
||||
templates_source: "{{ role_path }}/templates"
|
@ -1,2 +0,0 @@
|
||||
- name: "Docker compose steps for {{ current_svc_name }}"
|
||||
import_tasks: "{{ playbook_dir }}/contrib/docker_compose_template_task_list.yml"
|
@ -1,6 +0,0 @@
|
||||
---
|
||||
# vars file for roles/nextcloud/
|
||||
current_svc_name: nextcloud
|
||||
current_svc_path: "{{ my_svc_path }}/{{ current_svc_name }}"
|
||||
|
||||
templates_source: "{{ role_path }}/templates"
|
@ -1,2 +0,0 @@
|
||||
- name: "Docker compose steps for {{ current_svc_name }}"
|
||||
import_tasks: "{{ playbook_dir }}/contrib/docker_compose_template_task_list.yml"
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
current_svc_name: traefik
|
||||
current_svc_path: "{{ my_svc_path }}/{{ current_svc_name }}"
|
||||
|
||||
templates_source: "{{ role_path }}/templates"
|
@ -1,12 +1,7 @@
|
||||
- hosts: docker_hosts
|
||||
roles:
|
||||
- docker_host
|
||||
- traefik
|
||||
- authentik
|
||||
- gitea
|
||||
- nextcloud
|
||||
- jellyfin
|
||||
- arrstack
|
||||
- alpina
|
||||
post_tasks:
|
||||
- name: Docker prune objects
|
||||
docker_prune:
|
||||
|
Loading…
x
Reference in New Issue
Block a user