mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-05-07 13:53:05 +00:00
selinux - add missing config keys when needed
Previously the selinux module would only edit the state of found configuration keys SELINUX and SELINUXTYPE in /etc/selinux/config but would not add them with desired state if they were not found. Fixes #23 https://github.com/ansible-collections/ansible.posix/issues/23 Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
@@ -125,9 +125,15 @@ def set_config_state(module, state, configfile):
|
||||
tmpfd, tmpfile = tempfile.mkstemp()
|
||||
|
||||
with open(tmpfile, "w") as write_file:
|
||||
line_found = False
|
||||
for line in lines:
|
||||
if re.match(r'^SELINUX=.*$', line):
|
||||
line_found = True
|
||||
write_file.write(re.sub(r'^SELINUX=.*', stateline, line) + '\n')
|
||||
|
||||
if not line_found:
|
||||
write_file.write('SELINUX=%s\n' % state)
|
||||
|
||||
module.atomic_move(tmpfile, configfile)
|
||||
|
||||
|
||||
@@ -155,9 +161,15 @@ def set_config_policy(module, policy, configfile):
|
||||
tmpfd, tmpfile = tempfile.mkstemp()
|
||||
|
||||
with open(tmpfile, "w") as write_file:
|
||||
line_found = False
|
||||
for line in lines:
|
||||
if re.match(r'^SELINUXTYPE=.*$', line):
|
||||
line_found = True
|
||||
write_file.write(re.sub(r'^SELINUXTYPE=.*', policyline, line) + '\n')
|
||||
|
||||
if not line_found:
|
||||
write_file.write('SELINUXTYPE=%s\n' % policy)
|
||||
|
||||
module.atomic_move(tmpfile, configfile)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user