From 63fba50912a2aec9f342ffc03447e7df7ec63b60 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sat, 13 May 2023 18:47:07 +0000 Subject: [PATCH] respawn seboolean module when selinux is missing --- changelogs/fragments/460-respawn.yaml | 4 ++++ plugins/modules/seboolean.py | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/460-respawn.yaml diff --git a/changelogs/fragments/460-respawn.yaml b/changelogs/fragments/460-respawn.yaml new file mode 100644 index 0000000..cd0b29a --- /dev/null +++ b/changelogs/fragments/460-respawn.yaml @@ -0,0 +1,4 @@ +--- +minor_changes: + - "seboolean - respawn module to use the system python interpreter when the ``selinux`` python module is not available for ``ansible_python_interpreter`` + (https://github.com/ansible-collections/ansible.posix/pull/460)." diff --git a/plugins/modules/seboolean.py b/plugins/modules/seboolean.py index 657b7fa..0d23073 100644 --- a/plugins/modules/seboolean.py +++ b/plugins/modules/seboolean.py @@ -75,6 +75,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.six import binary_type from ansible.module_utils._text import to_bytes, to_text +from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL def get_runtime_status(ignore_selinux_state=False): @@ -281,6 +282,12 @@ def main(): supports_check_mode=True, ) + if not HAVE_SELINUX and not HAVE_SEMANAGE and HAS_RESPAWN_UTIL: + # Only respawn the module if both libraries are missing. + # If only one is available, then usage of the "wrong" (i.e. not the system one) + # python interpreter is likely not the problem. + respawn_module("selinux") + if not HAVE_SELINUX: module.fail_json(msg=missing_required_lib('libselinux-python'), exception=SELINUX_IMP_ERR)