From c13b040e67eacb4f22f2ea7650561fee627dbcb9 Mon Sep 17 00:00:00 2001 From: Ted Pearson Date: Thu, 14 May 2020 11:36:47 -0400 Subject: [PATCH] systemd: set scope default to "system" (#67006) - Make "system" default scope for systemd - Remove extra None checks since there is now a default --- changelogs/fragments/67006-systemd-scope-default.yaml | 2 ++ lib/ansible/modules/systemd.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/67006-systemd-scope-default.yaml diff --git a/changelogs/fragments/67006-systemd-scope-default.yaml b/changelogs/fragments/67006-systemd-scope-default.yaml new file mode 100644 index 00000000000..26cc9143a72 --- /dev/null +++ b/changelogs/fragments/67006-systemd-scope-default.yaml @@ -0,0 +1,2 @@ +minor_changes: + - systemd - default scope is now explicitly "system" \ No newline at end of file diff --git a/lib/ansible/modules/systemd.py b/lib/ansible/modules/systemd.py index eaae69b7f25..8329a46ca89 100644 --- a/lib/ansible/modules/systemd.py +++ b/lib/ansible/modules/systemd.py @@ -72,6 +72,7 @@ options: The user dbus process is normally started during normal login, but not during the run of Ansible tasks. Otherwise you will probably get a 'Failed to connect to bus: no such file or directory' error." choices: [ system, user, global ] + default: system version_added: "2.7" no_block: description: @@ -332,7 +333,7 @@ def main(): daemon_reload=dict(type='bool', default=False, aliases=['daemon-reload']), daemon_reexec=dict(type='bool', default=False, aliases=['daemon-reexec']), user=dict(type='bool'), - scope=dict(type='str', choices=['system', 'user', 'global']), + scope=dict(type='str', default='system', choices=['system', 'user', 'global']), no_block=dict(type='bool', default=False), ), supports_check_mode=True, @@ -367,7 +368,7 @@ def main(): # if scope is 'system' or None, we can ignore as there is no extra switch. # The other choices match the corresponding switch - if module.params['scope'] not in (None, 'system'): + if module.params['scope'] != 'system': systemctl += " --%s" % module.params['scope'] if module.params['no_block']: @@ -487,7 +488,7 @@ def main(): enabled = True elif rc == 1: # if not a user or global user service and both init script and unit file exist stdout should have enabled/disabled, otherwise use rc entries - if module.params['scope'] in (None, 'system') and \ + if module.params['scope'] == 'system' and \ not module.params['user'] and \ is_initd and \ not out.strip().endswith('disabled') and \