Refactor Ansible tasks to use fully qualified module names and improve code consistency

- Updated all tasks to use fully qualified module names (e.g., ansible.builtin.shell, ansible.builtin.copy) for clarity and to avoid ambiguity.
- Replaced deprecated 'yum' module with 'dnf' for package management on RedHat-based systems.
- Improved formatting and consistency in task definitions, including the use of double quotes for strings and consistent indentation.
- Removed unnecessary comments and whitespace to enhance readability.
- Ensured that conditions and loops are consistently formatted across all tasks.
This commit is contained in:
2026-07-20 23:09:30 +02:00
parent bc330beebf
commit 81398e847e
33 changed files with 745 additions and 844 deletions
+42 -44
View File
@@ -1,35 +1,34 @@
---
# ---
# Some Checks
# ---
- name: Check if file '/etc/postfix/relay_domains' exists
stat:
ansible.builtin.stat:
path: /etc/postfix/relay_domains
register: relay_domains_actual
- name: (copy_files.yml) Get checksum of '/etc/postfix/relay_domains'
set_fact:
ansible.builtin.set_fact:
relay_domains_sha1: "{{ relay_domains_actual.stat.checksum }}"
when:
- relay_domains_actual.stat.exists
# ---
# Copy files - main
# ---
- name: (copy_files.yml) Copy plain files
copy:
src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}'
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
owner: root
group: root
mode: '0644'
mode: "0644"
loop: "{{ copy_plain_files }}"
loop_control:
label: 'dest: {{ item.name }}'
when:
label: "dest: {{ item.name }}"
when:
- copy_plain_files is defined
- copy_plain_files|length > 0
tags:
@@ -37,16 +36,16 @@
- copy-plain-files
- name: (copy_files.yml) Copy plain files Postfix (/etc/postfix)
copy:
src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}'
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
owner: root
group: root
mode: '0644'
mode: "0644"
loop: "{{ copy_plain_files_postfix }}"
loop_control:
label: 'dest: {{ item.name }}'
when:
label: "dest: {{ item.name }}"
when:
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfix is defined
- copy_plain_files_postfix|length > 0
@@ -56,16 +55,16 @@
notify: "Reload postfwd"
- name: (copy_files.yml) Copy host specific plain files Postfix (/etc/postfix)
copy:
src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}'
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
owner: root
group: root
mode: '0644'
mode: "0644"
loop: "{{ copy_plain_files_postfix_host_specific }}"
loop_control:
label: 'dest: {{ item.name }}'
when:
label: "dest: {{ item.name }}"
when:
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfix_host_specific is defined
- copy_plain_files_postfix_host_specific|length > 0
@@ -75,16 +74,16 @@
notify: "Reload postfwd"
- name: (copy_files.yml) Copy plain files Postfix Firewall (postfwd)
copy:
src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}'
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
owner: root
group: root
mode: '0644'
mode: "0644"
loop: "{{ copy_plain_files_postfwd }}"
loop_control:
label: 'dest: {{ item.name }}'
when:
label: "dest: {{ item.name }}"
when:
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfwd is defined
- copy_plain_files_postfwd|length > 0
@@ -94,16 +93,16 @@
notify: "Reload postfwd"
- name: (copy_files.yml) Copy host specific plain files Postfix Firewall (postfwd)
copy:
src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}'
ansible.builtin.copy:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
owner: root
group: root
mode: '0644'
mode: "0644"
loop: "{{ copy_plain_files_postfwd_host_specific }}"
loop_control:
label: 'dest: {{ item.name }}'
when:
label: "dest: {{ item.name }}"
when:
- inventory_hostname in groups['mail_server']
- copy_plain_files_postfwd_host_specific is defined
- copy_plain_files_postfwd_host_specific|length > 0
@@ -112,17 +111,16 @@
- copy-plain-files
notify: "Reload postfwd"
- name: (copy_files.yml) Copy template files
template:
src: '{{ item.src_path }}'
dest: '{{ item.dest_path }}'
ansible.builtin.template:
src: "{{ item.src_path }}"
dest: "{{ item.dest_path }}"
owner: root
group: root
mode: '0644'
mode: "0644"
loop: "{{ copy_template_files }}"
loop_control:
label: 'dest: {{ item.name }}'
label: "dest: {{ item.name }}"
when:
- copy_template_files is defined
- copy_template_files|length > 0
@@ -135,18 +133,18 @@
# ---
- name: Get checksum oif (possible upodated) file '/etc/postfix/relay_domains' exists
stat:
ansible.builtin.stat:
path: /etc/postfix/relay_domains
register: relay_domains_new
- name: (copy_files.yml) Get checksum of '/etc/postfix/relay_domains'
set_fact:
ansible.builtin.set_fact:
relay_domains_sha1_new: "{{ relay_domains_new.stat.checksum }}"
when:
- relay_domains_new.stat.exists
- name: (copy_files.yml) Renew database /etc/postfix/relay_domains.db
shell: '/usr/sbin/postmap btree:/etc/postfix/relay_domains'
ansible.builtin.command: "/usr/sbin/postmap btree:/etc/postfix/relay_domains"
when:
- relay_domains_actual.stat.exists
- relay_domains_new.stat.exists