From 31a6a3e3d7ceda3c5d6c7a348e50b18dbb44e7c5 Mon Sep 17 00:00:00 2001 From: Rene Mewissen Date: Thu, 22 Oct 2026 18:22:34 +0200 Subject: [PATCH] facts: migrate bare ansible_* facts to ansible_facts[] ansible-core deprecates injecting top-level facts as variables (INJECT_FACTS_AS_VARS) and will stop doing so in 2.24. Convert all remaining bare fact references (ansible_default_ipv4/ipv6, os_family, distribution_release, date_time, ...) to the ansible_facts[] form. Also fixes a typo (ansbile_date_time) in the postfix backup task. --- roles/base/tasks/main.yml | 2 +- .../bastionhost/tasks/system_setup/package_hardening.yml | 4 ++-- roles/jitsimeet/tasks/prepare_system.yml | 2 +- roles/mailserver/tasks/configure_postfix.yml | 2 +- roles/mastodon/vars/main.yml | 2 +- roles/nameserver/tasks/install_bind.yml | 8 ++++---- roles/nameserver/tasks/install_powerdns_server.yml | 2 +- .../templates/powerdns-recursor-custom-config.j2 | 4 ++-- .../templates/powerdns-server-pri-api-config.j2 | 2 +- roles/nameserver/templates/powerdns-server-sec-config.j2 | 2 +- roles/nameserver/templates/unbound_network.conf.j2 | 8 ++++---- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index 731d0ad..240e0b4 100755 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -18,7 +18,7 @@ when: - wireguard is defined - wireguard == true - - ansible_default_ipv4.address | ansible.utils.ipaddr('public') | length > 0 + - ansible_facts['default_ipv4']['address'] | ansible.utils.ipaddr('public') | length > 0 ignore_errors: True - import_tasks: system_setup/git.yml # install software diff --git a/roles/bastionhost/tasks/system_setup/package_hardening.yml b/roles/bastionhost/tasks/system_setup/package_hardening.yml index 0bbf609..d04fb41 100755 --- a/roles/bastionhost/tasks/system_setup/package_hardening.yml +++ b/roles/bastionhost/tasks/system_setup/package_hardening.yml @@ -24,7 +24,7 @@ state: absent purge: true # Also removes configuration files register: deb_packages_removed - when: ansible_os_family == "Debian" + when: ansible_facts['os_family'] == "Debian" - name: system setup | package hardening | remove unnecessary packages (RedHat family) tags: packages,hardening,system @@ -41,7 +41,7 @@ - sudo state: absent register: rh_packages_removed - when: ansible_os_family == "RedHat" + when: ansible_facts['os_family'] == "RedHat" - name: Set fact if packages were removed set_fact: diff --git a/roles/jitsimeet/tasks/prepare_system.yml b/roles/jitsimeet/tasks/prepare_system.yml index 3dde8a4..9588c33 100755 --- a/roles/jitsimeet/tasks/prepare_system.yml +++ b/roles/jitsimeet/tasks/prepare_system.yml @@ -32,7 +32,7 @@ - name: jitsimeet | add prosody repository apt_repository: - repo: "deb [signed-by=/usr/share/keyrings/prosody-archive-keyring.gpg] https://packages.prosody.im/debian {{ ansible_distribution_release }} main" + repo: "deb [signed-by=/usr/share/keyrings/prosody-archive-keyring.gpg] https://packages.prosody.im/debian {{ ansible_facts['distribution_release'] }} main" state: present filename: prosody notify: apt_update diff --git a/roles/mailserver/tasks/configure_postfix.yml b/roles/mailserver/tasks/configure_postfix.yml index 6e7c936..b0bf2ad 100755 --- a/roles/mailserver/tasks/configure_postfix.yml +++ b/roles/mailserver/tasks/configure_postfix.yml @@ -1,6 +1,6 @@ - name: mailserver | postfix | backup running config shell: - cmd: "postconf >> /etc/postfix/main.cf-{{ ansible_date_time.date }}-{{ ansbile_date_time.time}}" + cmd: "postconf >> /etc/postfix/main.cf-{{ ansible_facts['date_time']['date'] }}-{{ ansible_facts['date_time']['time'] }}" - name: mailserver | postfix | configuration shell: cmd: "postconf {{item.key}}={{item.value}}" diff --git a/roles/mastodon/vars/main.yml b/roles/mastodon/vars/main.yml index d486f3c..8bb0881 100755 --- a/roles/mastodon/vars/main.yml +++ b/roles/mastodon/vars/main.yml @@ -10,7 +10,7 @@ rbenv_version: "v1.2.0" ruby_build_version: "v20220218" bundler_version: "2.1.4" node_major_version: "20" -os_family: "{{ ansible_os_family|lower }}" +os_family: "{{ ansible_facts['os_family'] | lower }}" mastodon_user: "mastodon" mastodon_home: "/home/{{ mastodon_user }}" mastodon_db_user: "{{ mastodon_user }}" diff --git a/roles/nameserver/tasks/install_bind.yml b/roles/nameserver/tasks/install_bind.yml index d6070c1..75dfe99 100755 --- a/roles/nameserver/tasks/install_bind.yml +++ b/roles/nameserver/tasks/install_bind.yml @@ -10,9 +10,9 @@ replace: "{{ item.option }}" validate: "{{ named_checkconf }} %s" loop: - - { regexp: '^\s*listen-on \{(?:[\s\n]*(?:\d{1,3}\.){3}\d{1,3};)*[\s\n]*\};', option: "\tlisten-on { {{ ansible_default_ipv4.address }}; };"} - - { regexp: '^\s*listen-on-v6 \{[\s\n]*any;[\s\n]*\};', option: "\tlisten-on-v6 { {{ ansible_default_ipv6.address }}; };"} - - { regexp: '^\s*listen-on-v6 \{(?:[\s\n]*[\da-z:]*;)[\s\n]*\};', option: "\tlisten-on-v6 { {{ ansible_default_ipv6.address }}; };"} + - { regexp: '^\s*listen-on \{(?:[\s\n]*(?:\d{1,3}\.){3}\d{1,3};)*[\s\n]*\};', option: "\tlisten-on { {{ ansible_facts['default_ipv4']['address'] }}; };"} + - { regexp: '^\s*listen-on-v6 \{[\s\n]*any;[\s\n]*\};', option: "\tlisten-on-v6 { {{ ansible_facts['default_ipv6']['address'] }}; };"} + - { regexp: '^\s*listen-on-v6 \{(?:[\s\n]*[\da-z:]*;)[\s\n]*\};', option: "\tlisten-on-v6 { {{ ansible_facts['default_ipv6']['address'] }}; };"} notify: restart_named - name: nameserver | bind | basic configuration cont'd @@ -20,7 +20,7 @@ path: "{{ named_conf_options }}" regexp: '^\s*listen-on \{.*\};' state: present - line: "\tlisten-on { {{ ansible_default_ipv4.address }}; };" + line: "\tlisten-on { {{ ansible_facts['default_ipv4']['address'] }}; };" insertafter: "options {" validate: "{{ named_checkconf }} %s" notify: restart_named \ No newline at end of file diff --git a/roles/nameserver/tasks/install_powerdns_server.yml b/roles/nameserver/tasks/install_powerdns_server.yml index 50fb5bf..838a859 100755 --- a/roles/nameserver/tasks/install_powerdns_server.yml +++ b/roles/nameserver/tasks/install_powerdns_server.yml @@ -71,7 +71,7 @@ path: "/etc/mysql/mariadb.conf.d/50-server.cnf" section: "mysqld" option: "bind-address" - value: "{{ ansible_default_ipv4.address }}" + value: "{{ ansible_facts['default_ipv4']['address'] }}" state: present no_extra_spaces: False # not required. Do not insert spaces before and after '=' symbol. notify: restart_mysqld diff --git a/roles/nameserver/templates/powerdns-recursor-custom-config.j2 b/roles/nameserver/templates/powerdns-recursor-custom-config.j2 index 23b96f9..07ee503 100755 --- a/roles/nameserver/templates/powerdns-recursor-custom-config.j2 +++ b/roles/nameserver/templates/powerdns-recursor-custom-config.j2 @@ -1,8 +1,8 @@ allow-from = 192.168.1.0/24, 192.168.3.0/24, 172.16.0.0/24, 127.0.0.0/8 dont-query = forward-zones-recurse = universe.local=192.168.1.3 -local-address = 127.0.0.1 {% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}{% else %}{{ ansible_default_ipv4.address }}{% endif %} +local-address = 127.0.0.1 {% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}{% else %}{{ ansible_facts['default_ipv4']['address'] }}{% endif %} local-port = {% if pdns_recursor_lport is defined %}{{ pdns_recursor_lport }}{% else %}53{% endif %} non-local-bind = yes -query-local-address = {{ ansible_default_ipv4.address }} {% if ansible_default_ipv6.address is defined %}, {{ ansible_default_ipv6.address }}{% endif %} {% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}{% endif %} \ No newline at end of file +query-local-address = {{ ansible_facts['default_ipv4']['address'] }} {% if ansible_facts['default_ipv6'] is defined %}, {{ ansible_facts['default_ipv6']['address'] }}{% endif %} {% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}{% endif %} \ No newline at end of file diff --git a/roles/nameserver/templates/powerdns-server-pri-api-config.j2 b/roles/nameserver/templates/powerdns-server-pri-api-config.j2 index a16b3a2..be6a08f 100755 --- a/roles/nameserver/templates/powerdns-server-pri-api-config.j2 +++ b/roles/nameserver/templates/powerdns-server-pri-api-config.j2 @@ -1,6 +1,6 @@ api = Yes api-key ={{ pdns_api_key | default(lookup('password', '/etc/powerdns/pdns.d/.api-key length=20')) }} webserver = Yes -#webserver-address = {% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}{% else %}{{ ansible_default_ipv4.address }}{% endif %} +#webserver-address = {% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}{% else %}{{ ansible_facts['default_ipv4']['address'] }}{% endif %} webserver-address = 0.0.0.0 webserver-allow-from = 127.0.0.1, [::1], 192.168.1.238 \ No newline at end of file diff --git a/roles/nameserver/templates/powerdns-server-sec-config.j2 b/roles/nameserver/templates/powerdns-server-sec-config.j2 index 61873ba..756d28a 100755 --- a/roles/nameserver/templates/powerdns-server-sec-config.j2 +++ b/roles/nameserver/templates/powerdns-server-sec-config.j2 @@ -1,4 +1,4 @@ include-dir=/etc/powerdns/pdns.d launch= -local-address={{ ansible_default_ipv4.address }}, [{{ ansible_default_ipv6.address }}], 127.0.0.1:553{% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}:553{% endif %} +local-address={{ ansible_facts['default_ipv4']['address'] }}, [{{ ansible_facts['default_ipv6']['address'] }}], 127.0.0.1:553{% if wg_local_ip is defined %}, {{ wg_local_ip | ansible.utils.ipaddr('address') }}:553{% endif %} security-poll-suffix= \ No newline at end of file diff --git a/roles/nameserver/templates/unbound_network.conf.j2 b/roles/nameserver/templates/unbound_network.conf.j2 index 58de5f1..fd5b690 100755 --- a/roles/nameserver/templates/unbound_network.conf.j2 +++ b/roles/nameserver/templates/unbound_network.conf.j2 @@ -3,14 +3,14 @@ server: {% if wg_local_ip is defined %} interface: {{ wg_local_ip | ansible.utils.ipaddr('address') }} {% else %} - interface: {{ ansible_default_ipv4.address }} + interface: {{ ansible_facts['default_ipv4']['address'] }} {% endif %} interface: 127.0.0.1 interface: 127.0.0.53 interface: ::1 - outgoing-interface: {{ ansible_default_ipv4.address }} - {% if ansible_default_ipv6.address is defined %} - outgoing-interface: {{ ansible_default_ipv6.address }} + outgoing-interface: {{ ansible_facts['default_ipv4']['address'] }} + {% if ansible_facts['default_ipv6'] is defined %} + outgoing-interface: {{ ansible_facts['default_ipv6']['address'] }} {% endif %} access-control: 192.168.1.0/24 allow access-control: 192.168.3.0/24 allow