mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
8a56aa322e
commit
7ea909418e
1 changed files with 18 additions and 4 deletions
|
@ -51,9 +51,16 @@ options:
|
||||||
user:
|
user:
|
||||||
description:
|
description:
|
||||||
- run systemctl talking to the service manager of the calling user, rather than the service manager
|
- 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
|
type: bool
|
||||||
default: 'no'
|
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:
|
no_block:
|
||||||
description:
|
description:
|
||||||
- Do not synchronously wait for the requested operation to finish.
|
- Do not synchronously wait for the requested operation to finish.
|
||||||
|
@ -299,6 +306,7 @@ def main():
|
||||||
masked=dict(type='bool'),
|
masked=dict(type='bool'),
|
||||||
daemon_reload=dict(type='bool', default=False, aliases=['daemon-reload']),
|
daemon_reload=dict(type='bool', default=False, aliases=['daemon-reload']),
|
||||||
user=dict(type='bool', default=False),
|
user=dict(type='bool', default=False),
|
||||||
|
scope=dict(type='str', default='system', choices=['system', 'user', 'global']),
|
||||||
no_block=dict(type='bool', default=False),
|
no_block=dict(type='bool', default=False),
|
||||||
),
|
),
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
|
@ -306,8 +314,13 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
systemctl = module.get_bin_path('systemctl', True)
|
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"
|
systemctl = systemctl + " --user"
|
||||||
|
if module.params['scope'] == 'user':
|
||||||
|
systemctl = systemctl + " --user"
|
||||||
|
if module.params['scope'] == 'global':
|
||||||
|
systemctl = systemctl + " --global"
|
||||||
if module.params['no_block']:
|
if module.params['no_block']:
|
||||||
systemctl = systemctl + " --no-block"
|
systemctl = systemctl + " --no-block"
|
||||||
if module.params['force']:
|
if module.params['force']:
|
||||||
|
@ -401,8 +414,9 @@ def main():
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
enabled = True
|
enabled = True
|
||||||
elif rc == 1:
|
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 a user or global 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 module.params['scope'] == 'system' and \
|
||||||
|
not module.params['user'] and \
|
||||||
is_initd and \
|
is_initd and \
|
||||||
(not out.strip().endswith('disabled') or sysv_is_enabled(unit)):
|
(not out.strip().endswith('disabled') or sysv_is_enabled(unit)):
|
||||||
enabled = True
|
enabled = True
|
||||||
|
|
Loading…
Reference in a new issue