Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions roles/karo-compose/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

---

# Setup
# setup

- name: Register docker directory status
ansible.builtin.stat:
Expand All @@ -19,7 +19,7 @@
fail_msg: "Docker directory not present, run `just install` to setup Docker."
quiet: true

- name: Assert stack group names
- name: Assert defined stack group names
ansible.builtin.assert:
that:
- stack_group_lookup is not false
Expand All @@ -33,7 +33,7 @@
vars:
stack_group_lookup: "{{ lookup('vars', stack_group, default=false) }}"

- name: Assert imported stack groups
- name: Assert symlinked stack groups declared
ansible.builtin.assert:
that: stack_group_dir.path in karo_compose_stack_groups
fail_msg: "Stack group '{{ stack_group_dir.path }}' missing from 'karo_compose_stack_groups'."
Expand All @@ -60,7 +60,7 @@
{% endfor %}
{{ expanded_stacks }}

- name: Assert provided stack name
- name: Assert supplied stack name
ansible.builtin.assert:
that: karo_compose_justfile_stack in (
karo_compose_expanded_stacks | map(attribute='name') | list
Expand All @@ -69,14 +69,14 @@
fail_msg: "Invalid stack name '{{ karo_compose_justfile_stack }}'."
quiet: true

# Actions
# actions

- name: Down stacks
become: true
become_user: dockeruser
tags: down
block:
- name: Down docker compose stacks
- name: Down compose stacks
ansible.builtin.include_tasks: down.yml
loop: "{{ karo_compose_expanded_stacks | reverse }}"
loop_control:
Expand All @@ -91,14 +91,14 @@
become_user: dockeruser
tags: up
block:
- name: Up docker compose stacks
- name: Up compose stacks
ansible.builtin.include_tasks: up.yml
loop: "{{ karo_compose_expanded_stacks }}"
loop_control:
loop_var: stack
label: "{{ stack.name }}"
vars:
stack_vars: "{{ lookup('vars', stack.namespace ~ '_stack') }}"
stack_host_vars: "{{ lookup('vars', stack.namespace ~ '_stack') }}"
stack_defaults: "{{ lookup('vars', stack.namespace ~ '_stack_defaults') }}"
stack_secrets: "{{ query('filetree', '../templates/' ~ stack.path ~ '/secrets') }}"
karo_compose_secrets_path: "/run/user/1001/karo-compose/{{ stack.path }}"
Expand Down
16 changes: 8 additions & 8 deletions roles/karo-compose/tasks/up.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

---

# deploy templates
# templates

- name: "Create compose stack directory for {{ stack.name }}"
- name: "Create directory for {{ stack.name }}"
ansible.builtin.file:
path: "/srv/docker/{{ stack.path }}"
mode: "0774"
state: directory

- name: "Merge compose variables for {{ stack.name }}"
- name: "Merge stack variables for {{ stack.name }}"
ansible.builtin.set_fact:
compose: "{{ stack_defaults | combine(stack_vars, recursive=true) }}"
stack_vars: "{{ stack_defaults | combine(stack_host_vars, recursive=true) }}"

- name: "Deploy compose templates for {{ stack.name }}"
- name: "Render templates for {{ stack.name }}"
ansible.builtin.template:
src: "{{ template.src }}"
dest: "/srv/docker/{{ stack.path }}/{{ template.path | splitext | first }}"
Expand All @@ -26,9 +26,9 @@
loop_var: template
label: "{{ template.path }}"

# handle secrets
# secrets

- name: Prepare secrets
- name: Handle secrets
when: stack_secrets | length > 0
block:
- name: Create tmpfs secrets directory
Expand All @@ -55,7 +55,7 @@
label: "{{ secret.path | splitext | first }}"
changed_when: false

# start services
# services

- name: Up compose stack {{ stack.name }}
community.docker.docker_compose_v2:
Expand Down