rhel-system-roles.selinux Fatal error

Dear Team,

I am new to Ansible and i am getting the following erro while running " rhel-system-roles.selinux". Could you please help to resolve this error.

Environment:

RHEL- 9

Ansible core - 2.12.2

python version = 3.9.10

TASK [rhel-system-roles.selinux : Install SELinux python2 tools] *********************************************************
fatal: [ss1]: FAILED! => {“msg”: “The conditional check ‘ansible_python_version is version(‘3’, ‘<’)’ failed. The error was: error while evaluating conditional (ansible_python_version is version(‘3’, ‘<’)): ‘ansible_python_version’ is undefined\n\nThe error appears to be in ‘/usr/share/ansible/roles/rhel-system-roles.selinux/tasks/main.yml’: line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n—\n- name: Install SELinux python2 tools\n ^ here\n”}

Thanks & Regards,
Kannan Ravi

The error was: error while evaluating conditional (ansible_python_version is version(‘3’, ‘<’)): ‘ansible_python_version’ is undefined

I don’t know why that would not be defined, but that is causing your error.

Walter

Hi,

this var needs gather_facts to be true or setup to be called with at least ‘min’ level of facts.

STEPHENs-iMac:ansible mahespth$ ansible-playbook ansible_python_version

[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [localhost] *****************************************************************************************************************************************************************************************************************

TASK [Do we have ansible_python_version] *****************************************************************************************************************************************************************************************
ok: [localhost] => {
“ansible_python_version”: “VARIABLE IS NOT DEFINED!”
}

TASK [gather some facts] *********************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Do we have ansible_python_version] *****************************************************************************************************************************************************************************************
ok: [localhost] => {
“ansible_python_version”: “3.6.5”
}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

STEPHENs-iMac:ansible mahespth$ cat ansible_python_version

What version of rhel-system-roles are you using? Current versions of the role have logic to explicitly call setup to get the facts required by the role:
https://github.com/linux-system-roles/selinux/blob/master/tasks/set_facts_packages.yml#L2
and python_version is among the facts:

ansible_facts required by the role

__selinux_required_facts:

  • distribution
  • distribution_major_version
  • python_version

Since you are using rhel-system-roles, this means you are a RHEL and/or an Ansible customer.
If you installed the rpm, use rpm -q rhel-system-roles
If you installed from AutomatIon Hub, use ansible-galaxy collection list or something like that.