mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 07:05:27 +01:00
The seboolean, selinux, firewalld, and firewalld_info modules depend on system bindings that are only available for the default system python interpreter. ansible-core is not packaged for the default system python interpreter on RHEL 8 and 9. When automatic interpreter discovery does not occur (e.g. when using implicit localhost [1]), ansible-core will not use the system interpreter to run ansible modules and the aforementioned modules will not work even if the bindings are installed. The RHEL ansible-core maintainers as well as the EPEL ansible and ansible-collection-* package maintainers (inc. me) have gotten multiple bug reports about this. We have been telling people to fix their setup to use the correct Python interpreter. Fortunately, ansible-core 2.11 and above have a module utility that'll respawn modules to use the correct system interpreter. [1] https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
# Copyright (c) 2023 Maxwell G <maxwell@gtmx.me>
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
"""
|
|
Helpers to respawn a module to run using the system interpreter
|
|
"""
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
try:
|
|
from ansible.module_utils.common import respawn
|
|
except ImportError:
|
|
HAS_RESPAWN_UTIL = False
|
|
else:
|
|
HAS_RESPAWN_UTIL = True
|
|
|
|
|
|
SYSTEM_PYTHON_INTERPRETERS = (
|
|
"/usr/bin/libexec/platform-python",
|
|
"/usr/bin/python3",
|
|
"/usr/bin/python2",
|
|
"/usr/bin/python",
|
|
)
|
|
|
|
|
|
def respawn_module(module):
|
|
"""
|
|
Respawn an ansible module to using the first interpreter in
|
|
SYSTEM_PYTHON_INTERPRETERS that contains `module`.
|
|
|
|
Args:
|
|
module (str): Name of python module to search for
|
|
|
|
Returns:
|
|
Returns None if the module cannot be respawned.
|
|
"""
|
|
if respawn.has_respawned():
|
|
return
|
|
interpreter = respawn.probe_interpreters_for_module(
|
|
SYSTEM_PYTHON_INTERPRETERS, module
|
|
)
|
|
if interpreter:
|
|
respawn.respawn_module(interpreter)
|