From 7ea909418e56f20fe27650fa1d4144d9668c9efe Mon Sep 17 00:00:00 2001 From: hi117 Date: Thu, 2 Aug 2018 19:05:20 -0400 Subject: [PATCH] Add scope parameter to systemd (#40179) * Added changes for Issue #38828, adds scope paramater to systemd module * Removed description for old paramater * Added version_added field for new option * Readded the user paramater as a deprecated paramater * Changed version for the scope paramater since I missed the release window --- lib/ansible/modules/system/systemd.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index 6217752cbe..b1c54d1137 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -51,9 +51,16 @@ options: user: description: - run systemctl talking to the service manager of the calling user, rather than the service manager - of the system. + of the system. This is deprecated and the scope paramater should be used instead. type: bool default: 'no' + scope: + description: + - run systemctl within a given service manager scope, either as the default system scope (system), + the current user's scope (user), or the scope of all users (global). + choices: [ system, user, global ] + default: 'system' + version_added: "2.7" no_block: description: - Do not synchronously wait for the requested operation to finish. @@ -299,6 +306,7 @@ def main(): masked=dict(type='bool'), daemon_reload=dict(type='bool', default=False, aliases=['daemon-reload']), user=dict(type='bool', default=False), + scope=dict(type='str', default='system', choices=['system', 'user', 'global']), no_block=dict(type='bool', default=False), ), supports_check_mode=True, @@ -306,8 +314,13 @@ def main(): ) systemctl = module.get_bin_path('systemctl', True) - if module.params['user']: + if module.params['user'] and module.params['scope'] == 'system': + module.deprecate("The 'user' paramater is being renamed to 'scope'", version=2.8) systemctl = systemctl + " --user" + if module.params['scope'] == 'user': + systemctl = systemctl + " --user" + if module.params['scope'] == 'global': + systemctl = systemctl + " --global" if module.params['no_block']: systemctl = systemctl + " --no-block" if module.params['force']: @@ -401,8 +414,9 @@ def main(): if rc == 0: enabled = True elif rc == 1: - # if not a user service and both init script and unit file exist stdout should have enabled/disabled, otherwise use rc entries - if not module.params['user'] and \ + # 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'] == 'system' and \ + not module.params['user'] and \ is_initd and \ (not out.strip().endswith('disabled') or sysv_is_enabled(unit)): enabled = True