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:
+47
-48
@@ -1,6 +1,6 @@
|
||||
---
|
||||
- name: (apt.yml) Delete Hetzner files 'hetzner-mirror.list' and 'hetzner-security-updates.list'
|
||||
file:
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
@@ -10,12 +10,12 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) update configuration file - /etc/apt/sources.list
|
||||
template:
|
||||
ansible.builtin.template:
|
||||
src: "etc/apt/sources.list.{{ ansible_facts['distribution'] }}.j2"
|
||||
dest: /etc/apt/sources.list
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
mode: "0644"
|
||||
register: apt_config_updated
|
||||
when:
|
||||
- apt_manage_sources_list|bool
|
||||
@@ -25,7 +25,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) Ensure Debian archive keyring is present for deb822 Signed-By (Debian >= 13)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: debian-archive-keyring
|
||||
state: present
|
||||
when:
|
||||
@@ -37,7 +37,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) check if legacy /etc/apt/sources.list exists (Debian >= 13)
|
||||
stat:
|
||||
ansible.builtin.stat:
|
||||
path: /etc/apt/sources.list
|
||||
register: apt_sources_list_stat
|
||||
when:
|
||||
@@ -48,7 +48,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) backup legacy /etc/apt/sources.list before deb822 migration (Debian >= 13)
|
||||
copy:
|
||||
ansible.builtin.copy:
|
||||
src: /etc/apt/sources.list
|
||||
dest: /etc/apt/sources.list.before-deb822
|
||||
remote_src: true
|
||||
@@ -66,7 +66,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) replace /etc/apt/sources.list with deb822 notice (Debian >= 13)
|
||||
copy:
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/apt/sources.list
|
||||
content: |
|
||||
# {{ ansible_managed }}
|
||||
@@ -85,7 +85,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) configure deb822 Debian repository (Debian >= 13)
|
||||
template:
|
||||
ansible.builtin.template:
|
||||
src: "etc/apt/deb822/debian.sources.j2"
|
||||
dest: /etc/apt/sources.list.d/debian.sources
|
||||
owner: root
|
||||
@@ -100,7 +100,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) configure deb822 security repository (Debian >= 13)
|
||||
template:
|
||||
ansible.builtin.template:
|
||||
src: "etc/apt/deb822/security.sources.j2"
|
||||
dest: /etc/apt/sources.list.d/security.sources
|
||||
owner: root
|
||||
@@ -115,7 +115,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) configure deb822 backports repository (Debian >= 13)
|
||||
template:
|
||||
ansible.builtin.template:
|
||||
src: "etc/apt/deb822/backports.sources.j2"
|
||||
dest: /etc/apt/sources.list.d/backports.sources
|
||||
owner: root
|
||||
@@ -133,7 +133,7 @@
|
||||
# If 'backports' was enabled in a previous run but is now disabled.
|
||||
#
|
||||
- name: (apt.yml) remove deb822 backports repository when disabled (Debian >= 13)
|
||||
file:
|
||||
ansible.builtin.file:
|
||||
path: /etc/apt/sources.list.d/backports.sources
|
||||
state: absent
|
||||
register: apt_config_removed_backports_sources
|
||||
@@ -148,7 +148,7 @@
|
||||
# Collect change states from all Debian >=13 deb822 source tasks so apt update
|
||||
# can force a fresh cache refresh when repository files changed.
|
||||
- name: (apt.yml) aggregate deb822 source changes (Debian >= 13)
|
||||
set_fact:
|
||||
ansible.builtin.set_fact:
|
||||
apt_config_updated:
|
||||
changed: >-
|
||||
{{
|
||||
@@ -166,7 +166,7 @@
|
||||
- apt-configuration
|
||||
|
||||
- name: (apt.yml) apt 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: apt_update|bool
|
||||
@@ -193,7 +193,7 @@
|
||||
- apt-webserver-pkgs
|
||||
|
||||
- name: (apt.yml) apt upgrade
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
upgrade: "{{ apt_upgrade_type }}"
|
||||
update_cache: true
|
||||
dpkg_options: "{{ apt_upgrade_dpkg_options | join(',') }}"
|
||||
@@ -206,7 +206,7 @@
|
||||
- apt-webserver-pkgs
|
||||
|
||||
- name: (apt.yml) Initial install debian packages (stretch)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_stretch }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when:
|
||||
@@ -217,7 +217,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install debian packages (buster)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_buster }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -230,7 +230,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install debian packages (bullseye)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_bullseye }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -243,7 +243,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install debian packages (bookworm)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_bookworm }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -256,7 +256,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install debian packages (trixie)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_trixie }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -269,7 +269,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install ubuntu packages (bionic)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_bionic }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -281,7 +281,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install ubuntu packages (xenial)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_xenial }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -293,7 +293,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install ubuntu packages (jammy)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_jammy }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -305,7 +305,7 @@
|
||||
- apt-initial-install
|
||||
|
||||
- name: (apt.yml) Initial install ubuntu packages (noble)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_initial_install_ubuntu_noble }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
environment:
|
||||
@@ -321,7 +321,7 @@
|
||||
# ---
|
||||
|
||||
- name: (apt.yml) Ensure we have CPU microcode from backports (debian stretch)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ microcode_package }}"
|
||||
state: present
|
||||
default_release: "{{ ansible_facts['distribution_release'] }}-backports"
|
||||
@@ -334,20 +334,21 @@
|
||||
- apt-microcode
|
||||
|
||||
- name: (apt.yml) Install CPU microcode (debian buster/bullseye/bookworm/trixie)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ microcode_package }}"
|
||||
state: present
|
||||
default_release: "{{ ansible_facts['distribution_release'] }}"
|
||||
when:
|
||||
- ansible_facts['distribution'] == "Debian"
|
||||
- ansible_facts['distribution_major_version'] == "10" or ansible_facts['distribution_major_version'] == "11" or ansible_facts['distribution_major_version'] == "12" or ansible_facts['distribution_major_version'] == "13"
|
||||
- ansible_facts['distribution_major_version'] == "10" or ansible_facts['distribution_major_version'] == "11" or ansible_facts['distribution_major_version']
|
||||
== "12" or ansible_facts['distribution_major_version'] == "13"
|
||||
- ansible_facts['processor']|string is search("Intel")
|
||||
tags:
|
||||
- apt-initial-install
|
||||
- apt-microcode
|
||||
|
||||
- name: (apt.yml) Install CPU microcode (ubuntu bionic)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ microcode_package }}"
|
||||
state: present
|
||||
default_release: "{{ ansible_facts['distribution_release'] }}"
|
||||
@@ -360,7 +361,7 @@
|
||||
- apt-microcode
|
||||
|
||||
- name: (apt.yml) Install CPU microcode (ubuntu xenial)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ microcode_package }}"
|
||||
state: present
|
||||
default_release: "{{ ansible_facts['distribution_release'] }}"
|
||||
@@ -373,7 +374,7 @@
|
||||
- apt-microcode
|
||||
|
||||
- name: (apt.yml) Install CPU microcode (ubuntu jammy)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ microcode_package }}"
|
||||
state: present
|
||||
default_release: "{{ ansible_facts['distribution_release'] }}"
|
||||
@@ -386,7 +387,7 @@
|
||||
- apt-microcode
|
||||
|
||||
- name: (apt.yml) Install lxc_host related packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_lxc_host_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when:
|
||||
@@ -395,7 +396,7 @@
|
||||
- apt-lxc-hosts-pkgs
|
||||
|
||||
- name: (apt.yml) Install docker related packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_docker_host_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when:
|
||||
@@ -404,7 +405,7 @@
|
||||
- apt-docker-hosts-pkgs
|
||||
|
||||
- name: (apt.yml) Install kvm_host related packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_kvm_host_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when:
|
||||
@@ -413,7 +414,7 @@
|
||||
- apt-kvm-hosts-pkgs
|
||||
|
||||
- name: (apt.yml) Install kvm_host related packages only debian 10 (buster)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_kvm_host_buster_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when:
|
||||
@@ -424,7 +425,7 @@
|
||||
- apt-kvm-hosts-pkgs
|
||||
|
||||
- name: (apt.yml) Install compiler related packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_compiler_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when: install_compiler_pkgs|bool
|
||||
@@ -432,7 +433,7 @@
|
||||
- apt-compiler-pkgs
|
||||
|
||||
- name: (apt.yml) Install postgresql_server related packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_postgresql_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when: install_postgresql_pkgs|bool
|
||||
@@ -440,7 +441,7 @@
|
||||
- apt-postgresql-server-pkgs
|
||||
|
||||
- name: (apt.yml) Install webserver related packages (Debian <= 12)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_webserver_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when:
|
||||
@@ -451,7 +452,7 @@
|
||||
- apt-webserver-pkgs
|
||||
|
||||
- name: (apt.yml) Install webserver related packages (Debian >= 13)
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_webserver_pkgs_trixie }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when:
|
||||
@@ -462,7 +463,7 @@
|
||||
- apt-webserver-pkgs
|
||||
|
||||
- name: (apt.yml) Install samba related packages
|
||||
package:
|
||||
ansible.builtin.package:
|
||||
pkg: "{{ apt_install_server_samba }}"
|
||||
state: present
|
||||
when:
|
||||
@@ -471,7 +472,7 @@
|
||||
- samba-server
|
||||
|
||||
- name: (apt.yml) Install extra packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_extra_pkgs }}"
|
||||
state: "{{ apt_install_state }}"
|
||||
when: apt_install_extra_pkgs|bool
|
||||
@@ -479,7 +480,7 @@
|
||||
- apt-extra-pkgs
|
||||
|
||||
- name: (apt.yml) Remove unwanted packages
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
name: "{{ apt_remove }}"
|
||||
state: absent
|
||||
purge: "{{ apt_remove_purge }}"
|
||||
@@ -487,7 +488,7 @@
|
||||
- apt-remove
|
||||
|
||||
- name: (apt.yml) autoremove
|
||||
apt:
|
||||
ansible.builtin.apt:
|
||||
autoremove: true
|
||||
dpkg_options: "{{ apt_upgrade_dpkg_options | join(',') }}"
|
||||
when: apt_autoremove|bool
|
||||
@@ -514,7 +515,7 @@
|
||||
|
||||
- name: (apt.yml) autoclean cache
|
||||
ansible.builtin.apt:
|
||||
autoclean: yes
|
||||
autoclean: true
|
||||
when: apt_clean | bool
|
||||
tags:
|
||||
- apt-clean
|
||||
@@ -528,11 +529,10 @@
|
||||
# link '/etc/mysql/my.cnf' in case mysql/mariadb was installed from source
|
||||
#
|
||||
- name: (apt.yml) Check if file '/usr/local/mysql/etc/my.cnf' exists
|
||||
stat:
|
||||
ansible.builtin.stat:
|
||||
path: /usr/local/mysql/etc/my.cnf
|
||||
register: usr_local_mysql_etc_my_cnf
|
||||
when: groups['mysql_server']|string is search(inventory_hostname) or
|
||||
groups['apache2_webserver']|string is search(inventory_hostname) or
|
||||
when: groups['mysql_server']|string is search(inventory_hostname) or groups['apache2_webserver']|string is search(inventory_hostname) or
|
||||
groups['nextcloud_server']|string is search(inventory_hostname)
|
||||
tags:
|
||||
- apt-webserver-pkgs
|
||||
@@ -548,15 +548,14 @@
|
||||
# - check_mysql_cnf
|
||||
|
||||
- name: (apt.yml) Create a symbolic link /etc/my.cnf -> /usr/local/mysql/etc/my.cnf
|
||||
file:
|
||||
ansible.builtin.file:
|
||||
src: /usr/local/mysql/etc/my.cnf
|
||||
dest: /etc/mysql/my.cnf
|
||||
owner: root
|
||||
group: root
|
||||
state: link
|
||||
when:
|
||||
- (groups['mysql_server']|string is search(inventory_hostname) or
|
||||
groups['apache2_webserver']|string is search(inventory_hostname) or
|
||||
- (groups['mysql_server']|string is search(inventory_hostname) or groups['apache2_webserver']|string is search(inventory_hostname) or
|
||||
groups['nextcloud_server']|string is search(inventory_hostname))
|
||||
- usr_local_mysql_etc_my_cnf.stat.exists
|
||||
tags:
|
||||
|
||||
Reference in New Issue
Block a user