Skip to content

[Deprecation] Task "Load distro-specific vars" uses legacy fact injection #79

@slymit

Description

@slymit

Description

When running this role on recent Ansible versions, a deprecation warning is triggered regarding INJECT_FACTS_AS_VARS. Starting with ansible-core 2.24, top-level facts (like ansible_os_family) will no longer be auto-injected as global variables.

Current Behavior

The role accesses the OS family fact directly:

- name: Load distro-specific vars
  include_vars: "{{ ansible_os_family }}.yml"
  tags: always

This produces the following warning:

TASK [ansible-docker-systemd-service : Load distro-specific vars] **************
[DEPRECATION WARNING]: INJECT_FACTS_AS_VARS default to `True` is deprecated, top-level facts will not be auto injected after the change. This feature will be removed from ansible-core version 2.24.
Origin: /home/slymit/.ansible/roles/ansible-docker-systemd-service/tasks/main.yml:3:17

1 ---
2 - name: Load distro-specific vars
3   include_vars: "{{ ansible_os_family }}.yml"
                  ^ column 17

Use `ansible_facts["fact_name"]` (no `ansible_` prefix) instead.

Environment

ansible [core 2.20.2]
  config file = None
  configured module search path = ['/home/slymit/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/slymit/Projects/my-app/.venv/lib/python3.13/site-packages/ansible
  ansible collection location = /home/slymit/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/slymit/Projects/my-app/.venv/bin/ansible
  python version = 3.13.3 (main, Jun  2 2025, 20:42:21) [GCC 15.1.1 20250425] (/home/slymit/Projects/my-app/.venv/bin/python3)
  jinja version = 3.1.6
  pyyaml version = 6.0.3 (with libyaml v0.2.5)

Expected Behavior

The role should use the ansible_facts dictionary to ensure compatibility with future Ansible versions (2.24+).

P. S.: Thanks for this role!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions