summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/systemd.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/modules/systemd.py')
-rw-r--r--lib/ansible/modules/systemd.py53
1 files changed, 22 insertions, 31 deletions
diff --git a/lib/ansible/modules/systemd.py b/lib/ansible/modules/systemd.py
index 7dec0446..3580fa5e 100644
--- a/lib/ansible/modules/systemd.py
+++ b/lib/ansible/modules/systemd.py
@@ -25,9 +25,8 @@ options:
aliases: [ service, unit ]
state:
description:
- - V(started)/V(stopped) are idempotent actions that will not run commands unless necessary.
- V(restarted) will always bounce the unit.
- V(reloaded) will always reload and if the service is not running at the moment of the reload, it is started.
+ - C(started)/C(stopped) are idempotent actions that will not run commands unless necessary.
+ C(restarted) will always bounce the unit. C(reloaded) will always reload.
type: str
choices: [ reloaded, restarted, started, stopped ]
enabled:
@@ -46,7 +45,7 @@ options:
daemon_reload:
description:
- Run daemon-reload before doing any other operations, to make sure systemd has read any changes.
- - When set to V(true), runs daemon-reload even if the module does not start or stop anything.
+ - When set to C(true), runs daemon-reload even if the module does not start or stop anything.
type: bool
default: no
aliases: [ daemon-reload ]
@@ -59,8 +58,8 @@ options:
version_added: "2.8"
scope:
description:
- - Run systemctl within a given service manager scope, either as the default system scope V(system),
- the current user's scope V(user), or the scope of all users V(global).
+ - Run systemctl within a given service manager scope, either as the default system scope C(system),
+ the current user's scope C(user), or the scope of all users C(global).
- "For systemd to work with 'user', the executing user must have its own instance of dbus started and accessible (systemd requirement)."
- "The user dbus process is normally started during normal login, but not during the run of Ansible tasks.
Otherwise you will probably get a 'Failed to connect to bus: no such file or directory' error."
@@ -86,61 +85,59 @@ attributes:
platform:
platforms: posix
notes:
- - Since 2.4, one of the following options is required O(state), O(enabled), O(masked), O(daemon_reload), (O(daemon_reexec) since 2.8),
- and all except O(daemon_reload) and (O(daemon_reexec) since 2.8) also require O(name).
- - Before 2.4 you always required O(name).
+ - Since 2.4, one of the following options is required C(state), C(enabled), C(masked), C(daemon_reload), (C(daemon_reexec) since 2.8),
+ and all except C(daemon_reload) and (C(daemon_reexec) since 2.8) also require C(name).
+ - Before 2.4 you always required C(name).
- Globs are not supported in name, i.e C(postgres*.service).
- The service names might vary by specific OS/distribution
- - The order of execution when having multiple properties is to first enable/disable, then mask/unmask and then deal with service state.
- It has been reported that systemctl can behave differently depending on the order of operations if you do the same manually.
requirements:
- A system managed by systemd.
'''
EXAMPLES = '''
- name: Make sure a service unit is running
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
state: started
name: httpd
- name: Stop service cron on debian, if running
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
name: cron
state: stopped
- name: Restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
state: restarted
daemon_reload: true
name: crond
- name: Reload service httpd, in all cases
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
name: httpd.service
state: reloaded
- name: Enable service httpd and ensure it is not masked
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
name: httpd
enabled: true
masked: no
- name: Enable a timer unit for dnf-automatic
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
name: dnf-automatic.timer
state: started
enabled: true
- name: Just force systemd to reread configs (2.4 and above)
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
daemon_reload: true
- name: Just force systemd to re-execute itself (2.8 and above)
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
daemon_reexec: true
- name: Run a user service when XDG_RUNTIME_DIR is not set on remote login
- ansible.builtin.systemd_service:
+ ansible.builtin.systemd:
name: myservice
state: started
scope: user
@@ -152,7 +149,7 @@ RETURN = '''
status:
description: A dictionary with the key=value pairs returned from C(systemctl show).
returned: success
- type: dict
+ type: complex
sample: {
"ActiveEnterTimestamp": "Sun 2016-05-15 18:28:49 EDT",
"ActiveEnterTimestampMonotonic": "8135942",
@@ -283,7 +280,7 @@ import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.facts.system.chroot import is_chroot
from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing
-from ansible.module_utils.common.text.converters import to_native
+from ansible.module_utils._text import to_native
def is_running_service(service_status):
@@ -370,7 +367,7 @@ def main():
if os.getenv('XDG_RUNTIME_DIR') is None:
os.environ['XDG_RUNTIME_DIR'] = '/run/user/%s' % os.geteuid()
- # Set CLI options depending on params
+ ''' Set CLI options depending on params '''
# 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'] != 'system':
@@ -394,19 +391,13 @@ def main():
if module.params['daemon_reload'] and not module.check_mode:
(rc, out, err) = module.run_command("%s daemon-reload" % (systemctl))
if rc != 0:
- if is_chroot(module) or os.environ.get('SYSTEMD_OFFLINE') == '1':
- module.warn('daemon-reload failed, but target is a chroot or systemd is offline. Continuing. Error was: %d / %s' % (rc, err))
- else:
- module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err))
+ module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err))
# Run daemon-reexec
if module.params['daemon_reexec'] and not module.check_mode:
(rc, out, err) = module.run_command("%s daemon-reexec" % (systemctl))
if rc != 0:
- if is_chroot(module) or os.environ.get('SYSTEMD_OFFLINE') == '1':
- module.warn('daemon-reexec failed, but target is a chroot or systemd is offline. Continuing. Error was: %d / %s' % (rc, err))
- else:
- module.fail_json(msg='failure %d during daemon-reexec: %s' % (rc, err))
+ module.fail_json(msg='failure %d during daemon-reexec: %s' % (rc, err))
if unit:
found = False