55 lines
1.9 KiB
YAML
55 lines
1.9 KiB
YAML
---
|
|
- name: Deploy Docker Service Configurations (Modified in Last 10 Minutes)
|
|
hosts: rinoa
|
|
vars:
|
|
template_base_path: "{{ playbook_dir }}/app-configs"
|
|
appdata_base_path: "~/.docker/config/appdata"
|
|
|
|
tasks:
|
|
- name: Find all Jinja2 templates
|
|
ansible.builtin.find:
|
|
paths: "{{ template_base_path }}"
|
|
patterns: "*.j2"
|
|
recurse: yes
|
|
register: jinja_templates
|
|
delegate_to: localhost
|
|
run_once: true
|
|
|
|
- name: Get parent directories modified in the last 10 minutes
|
|
ansible.builtin.command: >
|
|
find {{ template_base_path }} -mindepth 1 -maxdepth 1
|
|
-type d -mmin -10
|
|
register: modified_dirs
|
|
changed_when: false
|
|
delegate_to: localhost
|
|
run_once: true
|
|
|
|
- name: Set fact for recent directories
|
|
ansible.builtin.set_fact:
|
|
recent_dirs: "{{ modified_dirs.stdout_lines }}"
|
|
|
|
- name: Filter templates within recently modified folders
|
|
ansible.builtin.set_fact:
|
|
selected_templates: >-
|
|
{{ jinja_templates.files
|
|
| selectattr('path', 'search', recent_dirs | map('regex_escape') | map('regex_replace', '^', '') | join('|'))
|
|
| list }}
|
|
|
|
- name: Ensure target directories exist
|
|
ansible.builtin.file:
|
|
path: "{{ appdata_base_path }}/{{ item.path | regex_replace('^' + template_base_path + '/', '') | regex_replace('\\.j2$', '') | dirname }}"
|
|
state: directory
|
|
mode: '0755'
|
|
loop: "{{ selected_templates }}"
|
|
loop_control:
|
|
label: "{{ item.path }}"
|
|
|
|
- name: Render and deploy templates
|
|
ansible.builtin.template:
|
|
src: "{{ item.path }}"
|
|
dest: "{{ appdata_base_path }}/{{ item.path | regex_replace('^' + template_base_path + '/', '') | regex_replace('\\.j2$', '') }}"
|
|
mode: '0644'
|
|
loop: "{{ selected_templates }}"
|
|
loop_control:
|
|
label: "{{ item.path }}"
|