diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2023-04-27 16:15:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 16:15:24 -0400 |
commit | 9bd698b3a78ad9abc9d0b1775d8f67747a13b295 (patch) | |
tree | 330faa39419a54d934dd808ad03f710a2399b5cf | |
parent | d5e2e7a0a8ca9017a091922648430374539f878b (diff) | |
download | ansible-9bd698b3a78ad9abc9d0b1775d8f67747a13b295.tar.gz |
service module : remove flag confugration from openbsd enable/disable service (#80628)
fixes #66434
* removed flag setting from enable/disable on openbsd
service was changing permanent config on openbsd, which is not expected from the this module
* if in check mode, module should not stop at enable/disable
* simplify and clean up opensd service enable/disable
* does break for those that were using service for configuring flags
-rw-r--r-- | changelogs/fragments/service_fix_obsd.yml | 7 | ||||
-rw-r--r-- | lib/ansible/modules/service.py | 106 |
2 files changed, 22 insertions, 91 deletions
diff --git a/changelogs/fragments/service_fix_obsd.yml b/changelogs/fragments/service_fix_obsd.yml new file mode 100644 index 0000000000..ad4b890af7 --- /dev/null +++ b/changelogs/fragments/service_fix_obsd.yml @@ -0,0 +1,7 @@ +bugfixes: + - service module, does not permanently configure flags flags on Openbsd when enabling/disabling a service. + - service module, enable/disable is not a exclusive action in checkmode anymore. +breaking_changes: + - service module will not permanently configure variables/flags for openbsd when doing enable/disable operation anymore, + this module was never meant to do this type of work, just to manage the service state itself. A rcctl_config or similar + module should be created and used instead. diff --git a/lib/ansible/modules/service.py b/lib/ansible/modules/service.py index 69737e020c..49294c17fd 100644 --- a/lib/ansible/modules/service.py +++ b/lib/ansible/modules/service.py @@ -1191,107 +1191,31 @@ class OpenBsdService(Service): return self.execute_command("%s -f %s" % (self.svc_cmd, self.action)) def service_enable(self): + if not self.enable_cmd: return super(OpenBsdService, self).service_enable() - rc, stdout, stderr = self.execute_command("%s %s %s %s" % (self.enable_cmd, 'getdef', self.name, 'flags')) - - if stderr: - self.module.fail_json(msg=stderr) - - getdef_string = stdout.rstrip() - - # Depending on the service the string returned from 'getdef' may be - # either a set of flags or the boolean YES/NO - if getdef_string == "YES" or getdef_string == "NO": - default_flags = '' - else: - default_flags = getdef_string - - rc, stdout, stderr = self.execute_command("%s %s %s %s" % (self.enable_cmd, 'get', self.name, 'flags')) - - if stderr: - self.module.fail_json(msg=stderr) - - get_string = stdout.rstrip() - - # Depending on the service the string returned from 'get' may be - # either a set of flags or the boolean YES/NO - if get_string == "YES" or get_string == "NO": - current_flags = '' - else: - current_flags = get_string - - # If there are arguments from the user we use these as flags unless - # they are already set. - if self.arguments and self.arguments != current_flags: - changed_flags = self.arguments - # If the user has not supplied any arguments and the current flags - # differ from the default we reset them. - elif not self.arguments and current_flags != default_flags: - changed_flags = ' ' - # Otherwise there is no need to modify flags. - else: - changed_flags = '' - rc, stdout, stderr = self.execute_command("%s %s %s %s" % (self.enable_cmd, 'get', self.name, 'status')) + status_action = None if self.enable: - if rc == 0 and not changed_flags: - return - if rc != 0: - status_action = "set %s status on" % (self.name) - else: - status_action = '' - if changed_flags: - flags_action = "set %s flags %s" % (self.name, changed_flags) - else: - flags_action = '' - else: - if rc == 1: - return - - status_action = "set %s status off" % self.name - flags_action = '' - - # Verify state assumption - if not status_action and not flags_action: - self.module.fail_json(msg="neither status_action or status_flags is set, this should never happen") - - if self.module.check_mode: - self.module.exit_json(changed=True, msg="changing service enablement") - - status_modified = 0 - if status_action: - rc, stdout, stderr = self.execute_command("%s %s" % (self.enable_cmd, status_action)) - - if rc != 0: - if stderr: - self.module.fail_json(msg=stderr) - else: - self.module.fail_json(msg="rcctl failed to modify service status") + status_action = "on" + elif self.enable is not None: + # should be explicit False at this point + if rc != 1: + status_action = "off" - status_modified = 1 - - if flags_action: - rc, stdout, stderr = self.execute_command("%s %s" % (self.enable_cmd, flags_action)) + if status_action is not None: + self.changed = True + if not self.module.check_mode: + rc, stdout, stderr = self.execute_command("%s set %s status %s" % (self.enable_cmd, self.name, status_action)) - if rc != 0: - if stderr: - if status_modified: - error_message = "rcctl modified service status but failed to set flags: " + stderr - else: - error_message = stderr - else: - if status_modified: - error_message = "rcctl modified service status but failed to set flags" + if rc != 0: + if stderr: + self.module.fail_json(msg=stderr) else: - error_message = "rcctl failed to modify service flags" - - self.module.fail_json(msg=error_message) - - self.changed = True + self.module.fail_json(msg="rcctl failed to modify service status") class NetBsdService(Service): |