ansible-keycloak
ansible-keycloak copied to clipboard
Python 3 bindings missing for yum / controlling ansible_python_interpreter
Hi!
I'm getting errors on CentOS 7 when using Python 3 and yum (dnf is not installed):
PLAY [INSTALL - tasks for keycloak] ********************************************
TASK [Gathering Facts] *********************************************************
ok: [keycloak1]
TASK [nkinder.keycloak : check if all required variables are set] **************
skipping: [keycloak1]
TASK [nkinder.keycloak : Verify Python3 import] ********************************
ok: [keycloak1]
TASK [nkinder.keycloak : Set python interpreter to 3] **************************
ok: [keycloak1]
TASK [nkinder.keycloak : Set python interpreter to 2] **************************
skipping: [keycloak1]
TASK [nkinder.keycloak : create local download location] ***********************
ok: [keycloak1]
TASK [nkinder.keycloak : install dependencies] *********************************
failed: [keycloak1] (item=firewalld) => {"ansible_loop_var": "item", "changed": false, "item": "firewalld", "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}
failed: [keycloak1] (item=java-1.8.0-openjdk-headless) => {"ansible_loop_var": "item", "changed": false, "item": "java-1.8.0-openjdk-headless", "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}
failed: [keycloak1] (item=unzip) => {"ansible_loop_var": "item", "changed": false, "item": "unzip", "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}
failed: [keycloak1] (item=pyOpenSSL) => {"ansible_loop_var": "item", "changed": false, "item": "pyOpenSSL", "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}
The package module detects that yum is installed and tries to use it, but Python 3 lacks support for it. The common solution for this is to set ansible_python_interpreter as needed, but that's not possible as the variable is managed internally by tasks/python_2_3_test.yml, which will also default to Python 3 when both versions are installed (so having Python 2 becomes irrelevant to solve the problem).
This affects all CentOS with Python 3 and yum. Yum is still the default package manager, and Python 3 is needed in most scenarios now, including those that also have Python 2. This happens frequently with Ansible where there's a need to apply multiple roles, each with multiple, arbitrarily large dependency trees.
Would it be possible to have python_2_3_test.yml to run the autodetection only when ansible_python_interpreter isn't already set? I can test and send a patch for that. Note that it would be compatible with both the current version and the changes in #25 (and any other solution in that line) with a trivial modification. But it would preserve the ability to control this important variable from outside the role when it is needed.
Note: removing Python 3, or installing dnf, or removing the lines in main.yml that call python_2_3_test.yml are solutions that I tested and can confirm they work. But I think they carry a bigger toll on interop/usefulness when compared to the above.