Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change system_python variable to consider minor python version #56

Conversation

dmasteller4
Copy link
Contributor

@dmasteller4 dmasteller4 commented Nov 18, 2022

Similar to 'change to platform-python #48 #49', we were having an issue with python3-selinux binding looking in the wrong site packages directory when multiple versions of python are installed. This fix grabs more fields of platform.python_version_tuple(), ensuring it is getting the site packages from the python version that is actually running.

Ansible error encountered:

Note the discovered_interpreter_python is python3.8, but the selinux python bindings detection is being done under python3.7 /usr/local/lib/python3.7/site-packages

Using the commit from this PR fixed the problem for us.

fatal: [192.168.1.44]: FAILED! => changed=false 
  ansible_facts: {}
  failed_modules:
    ansible.legacy.setup:
      ansible_facts:
        discovered_interpreter_python: /usr/bin/python3.8
      exception: |-
        Traceback (most recent call last):
          File "/home/ec2-user/.ansible/tmp/ansible-tmp-1668811218.9790955-465955-71594733476064/AnsiballZ_setup.py", line 107, in <module>
            _ansiballz_main()
          File "/home/ec2-user/.ansible/tmp/ansible-tmp-1668811218.9790955-465955-71594733476064/AnsiballZ_setup.py", line 99, in _ansiballz_main
            invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
          File "/home/ec2-user/.ansible/tmp/ansible-tmp-1668811218.9790955-465955-71594733476064/AnsiballZ_setup.py", line 44, in invoke_module
            from ansible.module_utils import basic
          File "<frozen importlib._bootstrap>", line 991, in _find_and_load
          File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
          File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
          File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
          File "<frozen zipimport>", line 259, in load_module
          File "/tmp/ansible_ansible.legacy.setup_payload_tnvn_qci/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py", line 145, in <module>
          File "<frozen importlib._bootstrap>", line 991, in _find_and_load
          File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
          File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
          File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
          File "<frozen zipimport>", line 259, in load_module
          File "/tmp/ansible_ansible.legacy.setup_payload_tnvn_qci/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/common/process.py", line 9, in <module>
          File "<frozen importlib._bootstrap>", line 991, in _find_and_load
          File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
          File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
          File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
          File "<frozen zipimport>", line 259, in load_module
          File "/tmp/ansible_ansible.legacy.setup_payload_tnvn_qci/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/common/file.py", line 25, in <module>
          File "/home/ec2-user/.local/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
            check_system_sitepackages()
          File "/home/ec2-user/.local/lib/python3.8/site-packages/selinux/__init__.py", line 95, in check_system_sitepackages
            success = add_location(candidate)
          File "/home/ec2-user/.local/lib/python3.8/site-packages/selinux/__init__.py", line 65, in add_location
            reload(sys.modules["selinux"])
          File "/usr/lib64/python3.8/importlib/__init__.py", line 169, in reload
            _bootstrap._exec(spec, module)
          File "/usr/local/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
            check_system_sitepackages()
          File "/usr/local/lib/python3.8/site-packages/selinux/__init__.py", line 100, in check_system_sitepackages
            raise Exception(
        Exception: Failed to detect selinux python bindings at ['/usr/local/lib64/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages', '/usr/lib64/python3.7/site-packages', '/usr/lib/python3.7/site-packages']
      failed: true
      module_stderr: |-
        Shared connection to 10.1.1.95 closed.
      module_stdout: |-
        Traceback (most recent call last):
          File "/home/ec2-user/.ansible/tmp/ansible-tmp-1668811218.9790955-465955-71594733476064/AnsiballZ_setup.py", line 107, in <module>
            _ansiballz_main()
          File "/home/ec2-user/.ansible/tmp/ansible-tmp-1668811218.9790955-465955-71594733476064/AnsiballZ_setup.py", line 99, in _ansiballz_main
            invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
          File "/home/ec2-user/.ansible/tmp/ansible-tmp-1668811218.9790955-465955-71594733476064/AnsiballZ_setup.py", line 44, in invoke_module
            from ansible.module_utils import basic
          File "<frozen importlib._bootstrap>", line 991, in _find_and_load
          File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
          File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
          File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
          File "<frozen zipimport>", line 259, in load_module
          File "/tmp/ansible_ansible.legacy.setup_payload_tnvn_qci/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py", line 145, in <module>
          File "<frozen importlib._bootstrap>", line 991, in _find_and_load
          File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
          File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
          File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
          File "<frozen zipimport>", line 259, in load_module
          File "/tmp/ansible_ansible.legacy.setup_payload_tnvn_qci/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/common/process.py", line 9, in <module>
          File "<frozen importlib._bootstrap>", line 991, in _find_and_load
          File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
          File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
          File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
          File "<frozen zipimport>", line 259, in load_module
          File "/tmp/ansible_ansible.legacy.setup_payload_tnvn_qci/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/common/file.py", line 25, in <module>
          File "/home/ec2-user/.local/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
            check_system_sitepackages()
          File "/home/ec2-user/.local/lib/python3.8/site-packages/selinux/__init__.py", line 95, in check_system_sitepackages
            success = add_location(candidate)
          File "/home/ec2-user/.local/lib/python3.8/site-packages/selinux/__init__.py", line 65, in add_location
            reload(sys.modules["selinux"])
          File "/usr/lib64/python3.8/importlib/__init__.py", line 169, in reload
            _bootstrap._exec(spec, module)
          File "/usr/local/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
            check_system_sitepackages()
          File "/usr/local/lib/python3.8/site-packages/selinux/__init__.py", line 100, in check_system_sitepackages
            raise Exception(
        Exception: Failed to detect selinux python bindings at ['/usr/local/lib64/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages', '/usr/lib64/python3.7/site-packages', '/usr/lib/python3.7/site-packages']
      msg: |-
        MODULE FAILURE
        See stdout/stderr for the exact error
      rc: 1
  msg: |-
    The following modules failed to execute: ansible.legacy.setup

Fixes: #48
Fixes: #49

@charltonstanley charltonstanley force-pushed the dm/fix-for-system-python-variable branch from b3cae89 to 4e6cc72 Compare November 29, 2022 16:04
@ssbarnea ssbarnea added the bug Something isn't working label Dec 24, 2022
@ssbarnea ssbarnea changed the title bug: Change system_python variable Change system_python variable to consider minor python version Dec 24, 2022
@ssbarnea ssbarnea merged commit 2037b07 into pycontribs:main Dec 24, 2022
@charltonstanley charltonstanley deleted the dm/fix-for-system-python-variable branch December 27, 2022 20:50
@ghost
Copy link

ghost commented Jan 6, 2023

This change has caused a lot of issues with Ansible on our systems. We can no longer run Ansible from a Centos Stream 8 host unless we are installing Ansible in a venv created from the system Python (3.6). It would generally be fine for this to fail and not load the selinux bindings in our case because this is our Ansible controller but since this package is hard-coded to look only at /usr/bin/python... 🤷‍♂️

The 0.3.0 release has major breaking changes in it but it is a minor release made during a holiday, on a weekend. Seems like a questionable choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can we change this to /usr/libexec/platform-python ?
3 participants