refactor(copy_files.yml): simplify template file handling by removing redundant tasks
This commit is contained in:
@@ -161,43 +161,8 @@
|
|||||||
- copy-plain-files
|
- copy-plain-files
|
||||||
notify: "Reload postfwd"
|
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
|
- name: (copy_files.yml) copy template files
|
||||||
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:
|
ansible.builtin.template:
|
||||||
src: "{{ item.src_path }}"
|
src: "{{ item.src_path }}"
|
||||||
dest: "{{ item.dest_path }}"
|
dest: "{{ item.dest_path }}"
|
||||||
@@ -210,11 +175,6 @@
|
|||||||
when:
|
when:
|
||||||
- copy_template_files is defined
|
- copy_template_files is defined
|
||||||
- copy_template_files|length > 0
|
- 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:
|
tags:
|
||||||
- copy-files
|
- copy-files
|
||||||
- copy-template-files
|
- copy-template-files
|
||||||
|
|||||||
Reference in New Issue
Block a user