From 062d1a6fc7a021837318457e7046ff98c2f22796 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 20 Jul 2026 23:48:19 +0200 Subject: [PATCH] Refactor variable names in apt.yml for consistency and clarity --- roles/common/tasks/apt.yml | 77 +++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/roles/common/tasks/apt.yml b/roles/common/tasks/apt.yml index 7a7aab2..f5f0ea8 100644 --- a/roles/common/tasks/apt.yml +++ b/roles/common/tasks/apt.yml @@ -16,7 +16,7 @@ owner: root group: root mode: "0644" - register: apt_config_updated + register: common_apt_config_updated when: - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' @@ -39,7 +39,7 @@ - name: (apt.yml) check if legacy /etc/apt/sources.list exists (Debian >= 13) ansible.builtin.stat: path: /etc/apt/sources.list - register: apt_sources_list_stat + register: common_apt_sources_list_stat when: - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' @@ -60,8 +60,8 @@ - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' - (ansible_facts['distribution_major_version'] | int) >= 13 - - apt_sources_list_stat.stat.exists | default(false) - register: apt_sources_list_backup + - common_apt_sources_list_stat.stat.exists | default(false) + register: common_apt_sources_list_backup tags: - apt-configuration @@ -76,7 +76,7 @@ owner: root group: root mode: "0644" - register: apt_config_updated_sources_list + register: common_apt_config_updated_sources_list when: - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' @@ -91,7 +91,7 @@ owner: root group: root mode: "0644" - register: apt_config_updated_debian_sources + register: common_apt_config_updated_debian_sources when: - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' @@ -106,7 +106,7 @@ owner: root group: root mode: "0644" - register: apt_config_updated_security_sources + register: common_apt_config_updated_security_sources when: - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' @@ -121,7 +121,7 @@ owner: root group: root mode: "0644" - register: apt_config_updated_backports_sources + register: common_apt_config_updated_backports_sources when: - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' @@ -136,7 +136,7 @@ ansible.builtin.file: path: /etc/apt/sources.list.d/backports.sources state: absent - register: apt_config_removed_backports_sources + register: common_apt_config_removed_backports_sources when: - apt_manage_sources_list|bool - ansible_facts['distribution'] == 'Debian' @@ -149,14 +149,14 @@ # can force a fresh cache refresh when repository files changed. - name: (apt.yml) aggregate deb822 source changes (Debian >= 13) ansible.builtin.set_fact: - apt_config_updated: + common_apt_config_updated: changed: >- {{ - (apt_config_updated_sources_list.changed | default(false)) - or (apt_config_updated_debian_sources.changed | default(false)) - or (apt_config_updated_security_sources.changed | default(false)) - or (apt_config_updated_backports_sources.changed | default(false)) - or (apt_config_removed_backports_sources.changed | default(false)) + (common_apt_config_updated_sources_list.changed | default(false)) + or (common_apt_config_updated_debian_sources.changed | default(false)) + or (common_apt_config_updated_security_sources.changed | default(false)) + or (common_apt_config_updated_backports_sources.changed | default(false)) + or (common_apt_config_removed_backports_sources.changed | default(false)) }} when: - apt_manage_sources_list|bool @@ -168,7 +168,7 @@ - name: (apt.yml) apt update 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 }}" + cache_valid_time: "{{ 0 if common_apt_config_updated is defined and common_apt_config_updated.changed else apt_update_cache_valid_time }}" when: apt_update|bool tags: - apt-update @@ -181,9 +181,9 @@ - name: (apt.yml) Configure any half-installed packages 'dpkg --configure -a' ansible.builtin.command: dpkg --configure -a - register: _dpkg_configure - changed_when: (_dpkg_configure.stdout | default('')) | length > 0 - failed_when: _dpkg_configure.rc != 0 + register: common_dpkg_configure + changed_when: (common_dpkg_configure.stdout | default('')) | length > 0 + failed_when: common_dpkg_configure.rc != 0 when: apt_dpkg_configure|bool tags: - apt-dpkg-configure @@ -475,7 +475,12 @@ ansible.builtin.apt: name: "{{ apt_extra_pkgs }}" state: "{{ apt_install_state }}" - when: apt_install_extra_pkgs|bool + when: + - >- + (apt_install_extra_pkgs is boolean and apt_install_extra_pkgs) + or + (apt_install_extra_pkgs is not boolean and (apt_install_extra_pkgs | default([]) | length > 0)) + - apt_extra_pkgs | default([]) | length > 0 tags: - apt-extra-pkgs @@ -499,20 +504,6 @@ - apt-compiler-pkgs - apt-webserver-pkgs -#- name: (apt.yml) clean -# command: apt-get -y clean -# args: -# warn: false -# changed_when: false -# when: apt_clean|bool -# tags: -# - apt-clean -# - apt-initial-install -# - apt-microcode -# - apt-compiler-pkgs -# - apt-mysql-server-pkgs -# - apt-webserver-pkgs - - name: (apt.yml) autoclean cache ansible.builtin.apt: autoclean: true @@ -531,7 +522,7 @@ - name: (apt.yml) Check if file '/usr/local/mysql/etc/my.cnf' exists ansible.builtin.stat: path: /usr/local/mysql/etc/my.cnf - register: usr_local_mysql_etc_my_cnf + register: common_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 groups['nextcloud_server']|string is search(inventory_hostname) tags: @@ -539,13 +530,13 @@ - apt-mysql-server-pkgs - check_mysql_cnf -#- name: debug -# debug: -# msg: -# - usr_local_mysql_etc_my_cnf.stst.exists = {{ usr_local_mysql_etc_my_cnf.stat.exists }} -# - "Variable usr_local_mysql_etc_my_cnf: {{ usr_local_mysql_etc_my_cnf }}" -# tags: -# - check_mysql_cnf +# - name: debug +# debug: +# msg: +# - common_usr_local_mysql_etc_my_cnf.stst.exists = {{ common_usr_local_mysql_etc_my_cnf.stat.exists }} +# - "Variable common_usr_local_mysql_etc_my_cnf: {{ common_usr_local_mysql_etc_my_cnf }}" +# tags: +# - check_mysql_cnf - name: (apt.yml) Create a symbolic link /etc/my.cnf -> /usr/local/mysql/etc/my.cnf ansible.builtin.file: @@ -557,7 +548,7 @@ 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)) - - usr_local_mysql_etc_my_cnf.stat.exists + - common_usr_local_mysql_etc_my_cnf.stat.exists tags: - apt-webserver-pkgs - apt-mysql-server-pkgs