- collect-compose.yml: Fetches all compose files from docker_hosts - collect-env-templates.yml: Creates .env.example with secrets redacted - deploy-compose.yml: Pushes compose files to hosts (with optional restart) - diff-compose.yml: Shows differences before deploying Collected 23 compose files from 7 hosts: - replicant: 12 stacks (arr-stack, mealie, portainer, etc) - docker666: 4 stacks (unifi, gluetun, uptime, utils) - databases: 3 stacks (postgres, forgejo, utils) - download-stack: 2 stacks (download-stack, utils) - media-transcode: 1 stack (utils) - network-services: 1 stack (utils) - immich: 1 stack (utils)
80 lines
2.5 KiB
YAML
80 lines
2.5 KiB
YAML
---
|
|
- name: Deploy docker-compose files to hosts
|
|
hosts: docker_hosts
|
|
become: yes
|
|
gather_facts: no
|
|
vars:
|
|
restart_stacks: false
|
|
stack_filter: "" # Empty = all stacks, or specify stack name
|
|
|
|
tasks:
|
|
- name: Set appdata path
|
|
set_fact:
|
|
appdata_path: "{{ docker_appdata | default('/home/docker/appdata') }}"
|
|
|
|
- name: Find compose files for this host in repo
|
|
delegate_to: localhost
|
|
become: no
|
|
find:
|
|
paths: "{{ playbook_dir }}/../compose-files/{{ inventory_hostname }}"
|
|
patterns: "docker-compose.yml,docker-compose.yaml"
|
|
recurse: yes
|
|
register: repo_compose_files
|
|
|
|
- name: Filter stacks if specified
|
|
set_fact:
|
|
deploy_files: "{{ repo_compose_files.files | selectattr('path', 'search', stack_filter) | list }}"
|
|
when: stack_filter != ""
|
|
|
|
- name: Use all files if no filter
|
|
set_fact:
|
|
deploy_files: "{{ repo_compose_files.files }}"
|
|
when: stack_filter == ""
|
|
|
|
- name: Show files to deploy
|
|
debug:
|
|
msg: "Deploying {{ deploy_files | length }} compose files to {{ inventory_hostname }}"
|
|
|
|
- name: Ensure stack directories exist
|
|
file:
|
|
path: "{{ appdata_path }}/{{ item.path | dirname | basename }}"
|
|
state: directory
|
|
mode: '0755'
|
|
loop: "{{ deploy_files }}"
|
|
loop_control:
|
|
label: "{{ item.path | dirname | basename }}"
|
|
|
|
- name: Deploy compose files
|
|
copy:
|
|
src: "{{ item.path }}"
|
|
dest: "{{ appdata_path }}/{{ item.path | dirname | basename }}/docker-compose.yml"
|
|
mode: '0644'
|
|
backup: yes
|
|
loop: "{{ deploy_files }}"
|
|
loop_control:
|
|
label: "{{ item.path | dirname | basename }}/docker-compose.yml"
|
|
register: deployed_files
|
|
|
|
- name: Restart changed stacks
|
|
shell: |
|
|
cd {{ appdata_path }}/{{ item.item.path | dirname | basename }}
|
|
docker compose pull
|
|
docker compose up -d
|
|
loop: "{{ deployed_files.results }}"
|
|
loop_control:
|
|
label: "{{ item.item.path | dirname | basename }}"
|
|
when:
|
|
- restart_stacks | bool
|
|
- item.changed
|
|
register: restart_results
|
|
ignore_errors: yes
|
|
|
|
- name: Show restart results
|
|
debug:
|
|
msg: "Restarted: {{ item.item.item.path | dirname | basename }}"
|
|
loop: "{{ restart_results.results | default([]) }}"
|
|
loop_control:
|
|
label: "{{ item.item.item.path | dirname | basename | default('N/A') }}"
|
|
when:
|
|
- restart_stacks | bool
|
|
- item.changed | default(false)
|