From 34a9cf3e4d8cf1181a506618d1c5e2a5807b37d9 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Sat, 13 May 2023 18:56:38 +0000 Subject: [PATCH] respawn selinux module when selinux is missing --- changelogs/fragments/460-respawn.yaml | 2 ++ plugins/modules/selinux.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/changelogs/fragments/460-respawn.yaml b/changelogs/fragments/460-respawn.yaml index cd0b29a..7223b5d 100644 --- a/changelogs/fragments/460-respawn.yaml +++ b/changelogs/fragments/460-respawn.yaml @@ -2,3 +2,5 @@ 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)." + - "selinux - 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/selinux.py b/plugins/modules/selinux.py index 14110fe..0609462 100644 --- a/plugins/modules/selinux.py +++ b/plugins/modules/selinux.py @@ -107,6 +107,8 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.process import get_bin_path from ansible.module_utils.facts.utils import get_file_lines +from ansible_collections.ansible.posix.plugins.module_utils._respawn import respawn_module, HAS_RESPAWN_UTIL + # getter subroutines def get_config_state(configfile): @@ -236,6 +238,8 @@ def main(): ) if not HAS_SELINUX: + if HAS_RESPAWN_UTIL: + respawn_module("selinux") module.fail_json(msg=missing_required_lib('libselinux-python'), exception=SELINUX_IMP_ERR) # global vars