From 22f50e416dd1cd27f54079dc0f27b54f9d6fd7ae Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 6 Sep 2018 13:24:44 -0400 Subject: [PATCH] correct and clarify deprecation (#45234) * correct and clarify deprecation (cherry picked from commit 64c594d226bd9db658fe7690f3f5c67214b3a995) --- .../fragments/systemd_user_dep_fixes.yml | 2 + lib/ansible/modules/system/systemd.py | 38 ++++++++++++------- test/sanity/validate-modules/ignore.txt | 1 + 3 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 changelogs/fragments/systemd_user_dep_fixes.yml diff --git a/changelogs/fragments/systemd_user_dep_fixes.yml b/changelogs/fragments/systemd_user_dep_fixes.yml new file mode 100644 index 00000000000..b845d49369d --- /dev/null +++ b/changelogs/fragments/systemd_user_dep_fixes.yml @@ -0,0 +1,2 @@ +bugfixes: + - corrected and clarified 'user' option deprecation in systemd module in favor of 'scope' option. diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index 5ddc881f8e8..37a9e55a958 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -50,8 +50,9 @@ options: aliases: [ daemon-reload ] user: description: - - run systemctl talking to the service manager of the calling user, rather than the service manager - of the system. This is deprecated and the scope paramater should be used instead. + - (deprecated) run ``systemctl`` talking to the service manager of the calling user, rather than the service manager + of the system. + - This option is deprecated and will eventually be removed in 2.11. The ``scope`` option should be used instead. type: bool default: 'no' scope: @@ -305,26 +306,37 @@ def main(): force=dict(type='bool'), 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']), + user=dict(type='bool'), + scope=dict(type='str', choices=['system', 'user', 'global']), no_block=dict(type='bool', default=False), ), supports_check_mode=True, required_one_of=[['state', 'enabled', 'masked', 'daemon_reload']], + mutually_exclusive=[['scope', 'user']], ) systemctl = module.get_bin_path('systemctl', True) - 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" + + ''' Set CLI options depending on params ''' + if module.params['user'] is not None: + # handle user deprecation, mutually exclusive with scope + module.deprecate("The 'user' option is being replaced by 'scope'", version='2.11') + if module.params['user']: + module.params['scope'] = 'user' + else: + module.params['scope'] = 'system' + + # 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'): + systemctl += " --%s" % module.params['scope'] + if module.params['no_block']: - systemctl = systemctl + " --no-block" + systemctl += " --no-block" + if module.params['force']: - systemctl = systemctl + " --force" + systemctl += " --force" + unit = module.params['name'] rc = 0 out = err = '' diff --git a/test/sanity/validate-modules/ignore.txt b/test/sanity/validate-modules/ignore.txt index 122b32b0f01..092d17d6b58 100644 --- a/test/sanity/validate-modules/ignore.txt +++ b/test/sanity/validate-modules/ignore.txt @@ -1137,6 +1137,7 @@ lib/ansible/modules/system/selinux_permissive.py E322 lib/ansible/modules/system/seport.py E324 lib/ansible/modules/system/service.py E323 lib/ansible/modules/system/service.py E210 +lib/ansible/modules/system/systemd.py E324 lib/ansible/modules/system/solaris_zone.py E324 lib/ansible/modules/system/svc.py E322 lib/ansible/modules/system/svc.py E324