mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Fixed check_mode status to be the same as normal execution (#40721)
* Fixed check_mode status to be the same as normal execution * Now when setting the status to `disabled` in check_mode it correctly returns the state changed and prints a warning like it does in normal model. Before it always returned changed even if everything was set correctly and a reboot was required. * Add changelog entry Co-authored by: Strahinja Kustudic <kustodian@gmail.com>
This commit is contained in:
parent
f2d4912f29
commit
0781a7f68c
3 changed files with 166 additions and 7 deletions
|
@ -228,19 +228,20 @@ def main():
|
|||
changed = True
|
||||
|
||||
if state != runtime_state:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
if runtime_enabled:
|
||||
if state == 'disabled':
|
||||
if runtime_state != 'permissive':
|
||||
# Temporarily set state to permissive
|
||||
set_state(module, 'permissive')
|
||||
if not module.check_mode:
|
||||
set_state(module, 'permissive')
|
||||
module.warn('SELinux state temporarily changed from \'%s\' to \'permissive\'. State change will take effect next reboot.' % (runtime_state))
|
||||
changed = True
|
||||
else:
|
||||
module.warn('SELinux state change will take effect next reboot')
|
||||
reboot_required = True
|
||||
else:
|
||||
set_state(module, state)
|
||||
if not module.check_mode:
|
||||
set_state(module, state)
|
||||
msgs.append('SELinux state changed from \'%s\' to \'%s\'' % (runtime_state, state))
|
||||
|
||||
# Only report changes if the file is changed.
|
||||
|
@ -251,10 +252,9 @@ def main():
|
|||
reboot_required = True
|
||||
|
||||
if state != config_state:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True)
|
||||
if not module.check_mode:
|
||||
set_config_state(module, state, configfile)
|
||||
msgs.append('Config SELinux state changed from \'%s\' to \'%s\'' % (config_state, state))
|
||||
set_config_state(module, state, configfile)
|
||||
changed = True
|
||||
|
||||
module.exit_json(changed=changed, msg=', '.join(msgs), configfile=configfile, policy=policy, state=state, reboot_required=reboot_required)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue