|
|
@ -32,7 +32,7 @@ description:
|
|
|
|
- Controls systemd services on remote hosts.
|
|
|
|
- Controls systemd services on remote hosts.
|
|
|
|
options:
|
|
|
|
options:
|
|
|
|
name:
|
|
|
|
name:
|
|
|
|
required: true
|
|
|
|
required: false
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service).
|
|
|
|
- Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service).
|
|
|
|
aliases: ['unit', 'service']
|
|
|
|
aliases: ['unit', 'service']
|
|
|
@ -78,40 +78,44 @@ options:
|
|
|
|
Enqueued job will continue without Ansible blocking on its completion.
|
|
|
|
Enqueued job will continue without Ansible blocking on its completion.
|
|
|
|
version_added: "2.3"
|
|
|
|
version_added: "2.3"
|
|
|
|
notes:
|
|
|
|
notes:
|
|
|
|
- One option other than name is required.
|
|
|
|
- Since 2.4, one of the following options is required 'state', 'enabled', 'masked', 'daemon_reload', and all except 'daemon_reload' also require 'name'.
|
|
|
|
|
|
|
|
- Before 2.4 you always required 'name'.
|
|
|
|
requirements:
|
|
|
|
requirements:
|
|
|
|
- A system managed by systemd
|
|
|
|
- A system managed by systemd
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Example action to start service httpd, if not running
|
|
|
|
- name: Make sure a service is running
|
|
|
|
- systemd: state=started name=httpd
|
|
|
|
systemd: state=started name=httpd
|
|
|
|
|
|
|
|
|
|
|
|
# Example action to 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
|
|
|
|
|
|
|
|
|
|
|
|
# Example action to 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:
|
|
|
|
state: restarted
|
|
|
|
state: restarted
|
|
|
|
daemon_reload: yes
|
|
|
|
daemon_reload: yes
|
|
|
|
name: crond
|
|
|
|
name: crond
|
|
|
|
|
|
|
|
|
|
|
|
# Example action to reload service httpd, in all cases
|
|
|
|
- name: reload service httpd, in all cases
|
|
|
|
- systemd:
|
|
|
|
systemd:
|
|
|
|
name: httpd
|
|
|
|
name: httpd
|
|
|
|
state: reloaded
|
|
|
|
state: reloaded
|
|
|
|
|
|
|
|
|
|
|
|
# Example action to enable service httpd and ensure it is not masked
|
|
|
|
- name: enable service httpd and ensure it is not masked
|
|
|
|
- systemd:
|
|
|
|
systemd:
|
|
|
|
name: httpd
|
|
|
|
name: httpd
|
|
|
|
enabled: yes
|
|
|
|
enabled: yes
|
|
|
|
masked: no
|
|
|
|
masked: no
|
|
|
|
|
|
|
|
|
|
|
|
# Example action to enable a timer for dnf-automatic
|
|
|
|
- name: enable a timer for dnf-automatic
|
|
|
|
- systemd:
|
|
|
|
systemd:
|
|
|
|
name: dnf-automatic.timer
|
|
|
|
name: dnf-automatic.timer
|
|
|
|
state: started
|
|
|
|
state: started
|
|
|
|
enabled: True
|
|
|
|
enabled: True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: just force systemd to reread configs (2.4 and above)
|
|
|
|
|
|
|
|
systemd: daemon_reload=yes
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
RETURN = '''
|
|
|
@ -260,7 +264,7 @@ def main():
|
|
|
|
# initialize
|
|
|
|
# initialize
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
name = dict(required=True, type='str', aliases=['unit', 'service']),
|
|
|
|
name = dict(aliases=['unit', 'service']),
|
|
|
|
state = dict(choices=[ 'started', 'stopped', 'restarted', 'reloaded'], type='str'),
|
|
|
|
state = dict(choices=[ 'started', 'stopped', 'restarted', 'reloaded'], type='str'),
|
|
|
|
enabled = dict(type='bool'),
|
|
|
|
enabled = dict(type='bool'),
|
|
|
|
masked = dict(type='bool'),
|
|
|
|
masked = dict(type='bool'),
|
|
|
@ -286,6 +290,10 @@ def main():
|
|
|
|
'status': {},
|
|
|
|
'status': {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for requires in ('state', 'enabled', 'masked'):
|
|
|
|
|
|
|
|
if requires is not None and name is None:
|
|
|
|
|
|
|
|
module.fail_json(msg="name is also required when specifying %s" % requires)
|
|
|
|
|
|
|
|
|
|
|
|
# Run daemon-reload first, if requested
|
|
|
|
# Run daemon-reload first, if requested
|
|
|
|
if module.params['daemon_reload']:
|
|
|
|
if module.params['daemon_reload']:
|
|
|
|
(rc, out, err) = module.run_command("%s daemon-reload" % (systemctl))
|
|
|
|
(rc, out, err) = module.run_command("%s daemon-reload" % (systemctl))
|
|
|
|