[ANSIBLE] Automated PR for dagu-mariadb-bkup-config-check_2025-09-13T08-18-48 - #18 #18

Closed
gitea-sonarqube-bot wants to merge 48 commits from dagu-mariadb-bkup-config-check_2025-09-13T08-18-48 into main
Showing only changes of commit 16a392bb41 - Show all commits
+17 -14
View File
@@ -10,29 +10,32 @@
template_base_path: "{{ playbook_dir }}/../app-configs" template_base_path: "{{ playbook_dir }}/../app-configs"
pre_tasks: pre_tasks:
- name: Find all files for this host - name: Find all files for all hosts
ansible.builtin.find: ansible.builtin.find:
paths: "{{ template_base_path }}/{{ inventory_hostname }}" paths: "{{ template_base_path }}"
recurse: true recurse: true
register: host_files register: all_files
delegate_to: localhost
run_once: true
changed_when: false changed_when: false
- name: Build list of unique destination directories - name: Filter files for this host and build unique destination directories
ansible.builtin.set_fact: ansible.builtin.set_fact:
host_files: "{{ all_files.files | selectattr('path', 'match', '^' + template_base_path + '/' + inventory_hostname) | list }}"
dest_dirs: >- dest_dirs: >-
{{ {{
host_files.files host_files
| map(attribute='path') | map(attribute='path')
| map('relpath', template_base_path ~ '/' ~ inventory_hostname) | map('relpath', template_base_path ~ '/' ~ inventory_hostname)
| map('dirname') | map('dirname')
| map('regex_replace', '^(.*)$', appdata_base_path ~ '/\1') | map('regex_replace', '^(.*)$', hostvars[inventory_hostname]['appdata_base_path'] ~ '/\1')
| unique | unique
| list | list
}} }}
changed_when: false changed_when: false
tasks: tasks:
- name: Ensure destination directories exist (unique set) - name: Ensure destination directories exist
ansible.builtin.file: ansible.builtin.file:
path: "{{ item }}" path: "{{ item }}"
state: directory state: directory
@@ -40,18 +43,18 @@
loop: "{{ dest_dirs }}" loop: "{{ dest_dirs }}"
loop_control: loop_control:
label: "{{ item }}" label: "{{ item }}"
changed_when: false # mark pre-existing directories as unchanged changed_when: false
- name: Deploy Jinja2 templates (skip unchanged) - name: Deploy Jinja2 templates (skip unchanged)
ansible.builtin.template: ansible.builtin.template:
src: "{{ item.path }}" src: "{{ item.path }}"
dest: >- dest: >-
{{ appdata_base_path }}/{{ item.path {{ hostvars[inventory_hostname]['appdata_base_path'] }}/{{ item.path
| relpath(template_base_path ~ '/' ~ inventory_hostname) | relpath(template_base_path ~ '/' ~ inventory_hostname)
| regex_replace('\.j2$', '') }} | regex_replace('\.j2$', '') }}
mode: '0644' mode: '0644'
force: no # skip unchanged templates force: no
loop: "{{ host_files.files }}" loop: "{{ host_files }}"
loop_control: loop_control:
label: "{{ item.path }}" label: "{{ item.path }}"
when: item.path.endswith('.j2') when: item.path.endswith('.j2')
@@ -60,12 +63,12 @@
ansible.builtin.copy: ansible.builtin.copy:
src: "{{ item.path }}" src: "{{ item.path }}"
dest: >- dest: >-
{{ appdata_base_path }}/{{ item.path {{ hostvars[inventory_hostname]['appdata_base_path'] }}/{{ item.path
| relpath(template_base_path ~ '/' ~ inventory_hostname) }} | relpath(template_base_path ~ '/' ~ inventory_hostname) }}
mode: '0644' mode: '0644'
remote_src: false remote_src: false
force: no # skip unchanged files force: no
loop: "{{ host_files.files }}" loop: "{{ host_files }}"
loop_control: loop_control:
label: "{{ item.path }}" label: "{{ item.path }}"
when: not item.path.endswith('.j2') when: not item.path.endswith('.j2')