1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add force option to systemd module (#35925)

* Add force option to systemd module

* Use multi-line YAML syntax in examples

* Add version_added for new option
This commit is contained in:
Sam Doran 2018-02-20 20:47:29 -05:00 committed by ansibot
parent 5635c50f9b
commit 2bffcfa63b

View file

@ -33,6 +33,11 @@ options:
description: description:
- Whether the service should start on boot. B(At least one of state and enabled are required.) - Whether the service should start on boot. B(At least one of state and enabled are required.)
type: bool type: bool
force:
description:
- Whether to override existing symlinks.
type: bool
version_added: 2.6
masked: masked:
description: description:
- Whether the unit should be masked or not, a masked unit is impossible to start. - Whether the unit should be masked or not, a masked unit is impossible to start.
@ -65,10 +70,14 @@ requirements:
EXAMPLES = ''' EXAMPLES = '''
- name: Make sure a service is running - name: Make sure a service is running
systemd: state=started name=httpd systemd:
state: started
name: httpd
- name: stop service cron on debian, if running - name: stop service cron on debian, if running
systemd: name=cron state=stopped systemd:
name: cron
state: stopped
- name: restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes - name: restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes
systemd: systemd:
@ -94,7 +103,8 @@ EXAMPLES = '''
enabled: True enabled: True
- name: just force systemd to reread configs (2.4 and above) - name: just force systemd to reread configs (2.4 and above)
systemd: daemon_reload=yes systemd:
daemon_reload: yes
''' '''
RETURN = ''' RETURN = '''
@ -285,6 +295,7 @@ def main():
name=dict(type='str', aliases=['service', 'unit']), name=dict(type='str', aliases=['service', 'unit']),
state=dict(type='str', choices=['reloaded', 'restarted', 'started', 'stopped']), state=dict(type='str', choices=['reloaded', 'restarted', 'started', 'stopped']),
enabled=dict(type='bool'), enabled=dict(type='bool'),
force=dict(type='bool'),
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),
@ -299,6 +310,8 @@ def main():
systemctl = systemctl + " --user" systemctl = systemctl + " --user"
if module.params['no_block']: if module.params['no_block']:
systemctl = systemctl + " --no-block" systemctl = systemctl + " --no-block"
if module.params['force']:
systemctl = systemctl + " --force"
unit = module.params['name'] unit = module.params['name']
rc = 0 rc = 0
out = err = '' out = err = ''