feat(common): add host-tree file/template overrides and skip global items when host overrides exist

This commit is contained in:
2026-07-27 21:55:27 +02:00
parent b40d3249fb
commit f39babaf5d
33 changed files with 1148 additions and 43 deletions
+96 -5
View File
@@ -35,7 +35,31 @@
- copy-files
- copy-plain-files
- name: (copy_files.yml) Copy plain files Postfix (/etc/postfix)
- name: (copy_files.yml) HOST-TREE precheck host specific source directory on controller
ansible.builtin.stat:
path: "{{ role_path }}/files/{{ inventory_hostname }}"
delegate_to: localhost
become: false
register: common_host_dir
when:
- inventory_hostname in groups['mail_server']
tags:
- copy-files
- copy-plain-files
- name: (copy_files.yml) HOST-TREE precheck host specific template directory on controller
ansible.builtin.stat:
path: "{{ role_path }}/templates/{{ inventory_hostname }}"
delegate_to: localhost
become: false
register: common_host_template_dir
when:
- inventory_hostname in groups['mail_server']
tags:
- copy-files
- copy-template-files
- name: (copy_files.yml) GLOBAL copy plain files Postfix (/etc/postfix)
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
@@ -49,12 +73,16 @@
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfix is defined
- copy_plain_files_postfix|length > 0
- not (
common_host_dir.stat.exists and
(lookup('ansible.builtin.fileglob', role_path ~ '/files/' ~ inventory_hostname ~ item.dest_path, wantlist=True) | length > 0)
)
tags:
- copy-files
- copy-plain-files
notify: "Reload postfwd"
- name: (copy_files.yml) Copy host specific plain files Postfix (/etc/postfix)
- name: (copy_files.yml) FALLBACK legacy copy host specific plain files Postfix (/etc/postfix)
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
@@ -68,12 +96,13 @@
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfix_host_specific is defined
- copy_plain_files_postfix_host_specific|length > 0
- not common_host_dir.stat.exists
tags:
- copy-files
- copy-plain-files
notify: "Reload postfwd"
- name: (copy_files.yml) Copy plain files Postfix Firewall (postfwd)
- name: (copy_files.yml) GLOBAL copy plain files Postfix Firewall (postfwd)
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
@@ -87,12 +116,16 @@
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfwd is defined
- copy_plain_files_postfwd|length > 0
- not (
common_host_dir.stat.exists and
(lookup('ansible.builtin.fileglob', role_path ~ '/files/' ~ inventory_hostname ~ item.dest_path, wantlist=True) | length > 0)
)
tags:
- copy-files
- copy-plain-files
notify: "Reload postfwd"
- name: (copy_files.yml) Copy host specific plain files Postfix Firewall (postfwd)
- name: (copy_files.yml) FALLBACK legacy copy host specific plain files Postfix Firewall (postfwd)
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
@@ -106,12 +139,65 @@
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfwd_host_specific is defined
- copy_plain_files_postfwd_host_specific|length > 0
- not common_host_dir.stat.exists
tags:
- copy-files
- copy-plain-files
notify: "Reload postfwd"
- name: (copy_files.yml) Copy template files
- name: (copy_files.yml) HOST-TREE copy all host specific files by directory structure
ansible.builtin.copy:
src: "{{ role_path }}/files/{{ inventory_hostname }}/"
dest: "/"
owner: root
group: root
mode: preserve
when:
- inventory_hostname in groups['mail_server']
- common_host_dir.stat.exists
- common_host_dir.stat.isdir
tags:
- copy-files
- copy-plain-files
notify: "Reload postfwd"
- name: (copy_files.yml) HOST-TREE collect host specific template files by directory structure
ansible.builtin.find:
paths: "{{ role_path }}/templates/{{ inventory_hostname }}"
recurse: true
file_type: file
patterns: "*.j2"
delegate_to: localhost
become: false
register: common_host_template_files
when:
- inventory_hostname in groups['mail_server']
- common_host_template_dir.stat.exists
- common_host_template_dir.stat.isdir
tags:
- copy-files
- copy-template-files
- name: (copy_files.yml) HOST-TREE render host specific template files by directory structure
ansible.builtin.template:
src: "{{ item.path }}"
dest: "/{{ item.path | regex_replace('^' ~ (role_path ~ '/templates/' ~ inventory_hostname ~ '/'), '') | regex_replace('\\.j2$', '') }}"
owner: root
group: root
mode: "0644"
loop: "{{ common_host_template_files.files }}"
loop_control:
label: "dest: /{{ item.path | regex_replace('^' ~ (role_path ~ '/templates/' ~ inventory_hostname ~ '/'), '') | regex_replace('\\.j2$', '') }}"
when:
- inventory_hostname in groups['mail_server']
- common_host_template_dir.stat.exists
- common_host_template_dir.stat.isdir
- common_host_template_files.files | length > 0
tags:
- copy-files
- copy-template-files
- name: (copy_files.yml) GLOBAL copy template files (variable list)
ansible.builtin.template:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
@@ -124,6 +210,11 @@
when:
- copy_template_files is defined
- copy_template_files|length > 0
- not (
inventory_hostname in groups['mail_server'] and
common_host_template_dir.stat.exists and
(lookup('ansible.builtin.fileglob', role_path ~ '/templates/' ~ inventory_hostname ~ item.dest_path ~ '.j2', wantlist=True) | length > 0)
)
tags:
- copy-files
- copy-template-files