[PATCH 10/12] playbooks: migrate ansible_env and ansible_os_family to ansible_facts

Daniel Gomez <[email protected]> Thu, 23 Apr 2026 13:31:02 +0200
Newsgroups dev.linux.lists.kdevops
Message-ID <20260423-kdevops-series-c-qemu-system-units-v1-10-b7bab3225a36@samsung.com>
From: Daniel Gomez <[email protected]>

The top-level ansible_* fact injection that Ansible's
INJECT_FACTS_AS_VARS default enables is deprecated and slated
for removal in ansible-core 2.24. Tasks that read ansible_env
or ansible_os_family directly now emit a deprecation warning
on every play. Switch the NIXOS role's fact references to
ansible_facts.env and ansible_facts.os_family so it keeps
working without the injection shim and stays silent under the
future default.

Generated-by: Claude AI
Signed-off-by: Daniel Gomez <[email protected]>
---
 playbooks/roles/nixos/tasks/destroy.yml       | 2 +-
 playbooks/roles/nixos/tasks/install_deps.yml  | 4 ++--
 playbooks/roles/nixos/tasks/libvirt_build.yml | 2 +-
 playbooks/roles/nixos/tasks/ssh_access.yml    | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/playbooks/roles/nixos/tasks/destroy.yml b/playbooks/roles/nixos/tasks/destroy.yml
index 8943e197..263eaf45 100644
--- a/playbooks/roles/nixos/tasks/destroy.yml
+++ b/playbooks/roles/nixos/tasks/destroy.yml
@@ -35,7 +35,7 @@
           '' \
           '' \
           '' \
-          {{ nixos_ssh_config_file | default(ansible_env.HOME + '/.ssh/config') }} \
+          {{ nixos_ssh_config_file | default(ansible_facts.env.HOME + '/.ssh/config') }} \
           '' \
           'NixOS VM'
       loop: "{{ groups['all'] | reject('equalto', 'localhost') | list }}"
diff --git a/playbooks/roles/nixos/tasks/install_deps.yml b/playbooks/roles/nixos/tasks/install_deps.yml
index 98a517ea..ec3c2702 100644
--- a/playbooks/roles/nixos/tasks/install_deps.yml
+++ b/playbooks/roles/nixos/tasks/install_deps.yml
@@ -40,7 +40,7 @@
           - libvirt-daemon-system
           - libvirt-clients
         state: present
-      when: ansible_os_family == "Debian"
+      when: ansible_facts.os_family == "Debian"
 
     - name: Ensure libvirt is installed (RedHat)
       become: true
@@ -50,4 +50,4 @@
           - qemu-kvm
           - libvirt-daemon
         state: present
-      when: ansible_os_family == "RedHat"
+      when: ansible_facts.os_family == "RedHat"
diff --git a/playbooks/roles/nixos/tasks/libvirt_build.yml b/playbooks/roles/nixos/tasks/libvirt_build.yml
index 23a7c317..4603b023 100644
--- a/playbooks/roles/nixos/tasks/libvirt_build.yml
+++ b/playbooks/roles/nixos/tasks/libvirt_build.yml
@@ -20,7 +20,7 @@
           - "{{ nixos_config_dir }}/{{ item }}/result"
         creates: "{{ nixos_config_dir }}/{{ item }}/result"
       environment:
-        PATH: "/nix/var/nix/profiles/default/bin:{{ ansible_env.PATH | default('/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') }}"
+        PATH: "/nix/var/nix/profiles/default/bin:{{ ansible_facts.env.PATH | default('/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') }}"
         NIX_CONFIG: "{{ ('substituters = ' ~ nixos_mirror_url ~ ' https://cache.nixos.org') if (nixos_use_local_mirror | default(false) | bool and (nixos_mirror_url | default('') | length > 0)) else omit }}"
       loop: "{{ groups['all'] | reject('equalto', 'localhost') | list }}"
       loop_control:
diff --git a/playbooks/roles/nixos/tasks/ssh_access.yml b/playbooks/roles/nixos/tasks/ssh_access.yml
index 43cf3a37..7964940b 100644
--- a/playbooks/roles/nixos/tasks/ssh_access.yml
+++ b/playbooks/roles/nixos/tasks/ssh_access.yml
@@ -53,7 +53,7 @@
           {{ nixos_vm_ips[item] }} \
           {{ ansible_cfg_ssh_port }} \
           kdevops \
-          {{ nixos_ssh_config_file | default(ansible_env.HOME + '/.ssh/config') }} \
+          {{ nixos_ssh_config_file | default(ansible_facts.env.HOME + '/.ssh/config') }} \
           {{ ssh_key_path_for_config.stdout | trim }} \
           'NixOS VM'
       loop: "{{ groups['all'] | reject('equalto', 'localhost') | list }}"

-- 
2.53.0