1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Apply SELinux context only if cron_file param exists

Use selinux calls in module_utils/basic instead of native selinux bindings

Fixes #18768
This commit is contained in:
Evan Kaufman 2016-12-24 18:57:13 -08:00 committed by Brian Coca
parent 07a517aebd
commit ad9c25a54f

View file

@ -237,12 +237,6 @@ import tempfile
import platform
import pipes
try:
import selinux
HAS_SELINUX = True
except ImportError:
HAS_SELINUX = False
CRONCMD = "/usr/bin/crontab"
class CronTabError(Exception):
@ -345,8 +339,8 @@ class CronTab(object):
self.module.fail_json(msg=err)
# set SELinux permissions
if HAS_SELINUX:
selinux.selinux_lsetfilecon_default(self.cron_file)
if self.module.selinux_enabled() and self.cron_file:
self.module.set_default_selinux_context(self.cron_file, False)
def do_comment(self, name):
return "%s%s" % (self.ansible, name)