Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct and clarify deprecation #45234

Merged
merged 5 commits into from Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 25 additions & 13 deletions lib/ansible/modules/system/systemd.py
Expand Up @@ -50,8 +50,9 @@
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:
Expand Down Expand Up @@ -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 = ''
Expand Down
1 change: 1 addition & 0 deletions test/sanity/validate-modules/ignore.txt
Expand Up @@ -1134,6 +1134,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
Expand Down