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
+23 -29
View File
@@ -1,12 +1,11 @@
---
# ---
# Install 'bind' apt based OS
# ---
- name: (caching-nameserver.yml) update
apt:
ansible.builtin.apt:
update_cache: true
cache_valid_time: "{{ 0 if apt_config_updated is defined and apt_config_updated.changed else apt_update_cache_valid_time }}"
when:
@@ -26,9 +25,8 @@
tags:
- apt-caching-nameserver
- name: (caching-nameserver.yml) upgrade
apt:
ansible.builtin.apt:
upgrade: "{{ apt_upgrade_type }}"
update_cache: true
dpkg_options: "{{ apt_upgrade_dpkg_options | join(',') }}"
@@ -38,9 +36,8 @@
tags:
- apt-caching-nameserver
- name: (caching-nameserver.yml) Install bind packages (using apt)
apt:
ansible.builtin.apt:
name: "{{ apt_bind_pkgs }}"
state: present
when:
@@ -54,10 +51,10 @@
# ---
- name: (yum.yml) Install system updates for centos systems
yum:
name: '*'
ansible.builtin.dnf:
name: "*"
state: latest
update_cache: yes
update_cache: true
#cache_valid_time: 3600
when:
- ansible_facts.os_family == "RedHat"
@@ -66,7 +63,7 @@
- yum-update
- name: (yum.yml) Install bind packages (using yum)
yum:
ansible.builtin.dnf:
name: "{{ yum_bind_pks }}"
state: "{{ yum_install_state }}"
when:
@@ -80,30 +77,29 @@
# --
- name: (caching-nameserver.yml) Create directory /var/log/named if it does not exist
file:
ansible.builtin.file:
path: /var/log/named
state: directory
owner: bind
group: bind
mode: '0755'
mode: "0755"
when:
- ansible_facts["distribution"] == "Debian"
- name: (caching-nameserver.yml) update named.conf.options configuration file (normal server)
template:
ansible.builtin.template:
src: etc/bind/named.conf.options.j2
dest: /etc/bind/named.conf.options
backup: yes
backup: true
owner: root
group: bind
mode: 0644
mode: "0644"
#validate: visudo -cf %s
notify: Reload bind9
tags:
- apt-caching-nameserver
- caching-nameserver
when:
when:
- ansible_facts["distribution"] == "Debian"
- inventory_hostname not in groups["gateway_server"]
@@ -112,44 +108,42 @@
# In case of gateway gateway servers ONLY if bind ption file NOT exists
#
- name: Check if file '/etc/bind/named.conf.options' exists
stat:
ansible.builtin.stat:
path: /etc/bind/named.conf.options
register: file_named_conf_options
- name: (caching-nameserver.yml) update named.conf.options configuration file (gateway server)
template:
ansible.builtin.template:
src: etc/bind/named.conf.options.gateway.j2
dest: /etc/bind/named.conf.options
backup: yes
backup: true
owner: root
group: bind
mode: 0644
mode: "0644"
#validate: visudo -cf %s
notify: Reload bind9
tags:
- apt-caching-nameserver
- caching-nameserver
when:
when:
- ansible_facts["distribution"] == "Debian"
- inventory_hostname in groups["gateway_server"]
# - not file_named_conf_options.stat.exists
# --------------------
- name: (caching-nameserver.yml) Add 127.0.0.1 as first nameserver entry to /etc/resolv.conf
lineinfile:
ansible.builtin.lineinfile:
path: /etc/resolv.conf
line: nameserver 127.0.0.1
firstmatch: yes
insertbefore: '^nameserver'
firstmatch: true
insertbefore: "^nameserver"
state: present
owner: root
group: root
mode: '0644'
mode: "0644"
tags:
- apt-caching-nameserver
when:
when:
- ansible_facts["distribution"] == "Debian"
- not systemd_resolved