ansible.builtin.systemd – Manage services¶
Note
This module is part of ansible-base
and included in all Ansible
installations. In most cases, you can use the short module name
systemd even without specifying the collections:
keyword.
Despite that, we recommend you use the FQCN for easy linking to the module
documentation and to avoid conflicting with other collections that may have
the same module name.
New in version 2.2: of ansible.builtin
Requirements¶
The below requirements are needed on the host that executes this module.
- A system managed by systemd.
Parameters¶
Notes¶
Note
- Since 2.4, one of the following options is required ‘state’, ‘enabled’, ‘masked’, ‘daemon_reload’, (‘daemon_reexec’ since 2.8), and all except ‘daemon_reload’ (and ‘daemon_reexec’ since 2.8) also require ‘name’.
- Before 2.4 you always required ‘name’.
- Globs are not supported in name, i.e
postgres*.service
.
Examples¶
- name: Make sure a service is running
systemd:
state: started
name: httpd
- name: Stop service cron on debian, if running
systemd:
name: cron
state: stopped
- name: Restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes
systemd:
state: restarted
daemon_reload: yes
name: crond
- name: Reload service httpd, in all cases
systemd:
name: httpd
state: reloaded
- name: Enable service httpd and ensure it is not masked
systemd:
name: httpd
enabled: yes
masked: no
- name: Enable a timer for dnf-automatic
systemd:
name: dnf-automatic.timer
state: started
enabled: yes
- name: Just force systemd to reread configs (2.4 and above)
systemd:
daemon_reload: yes
- name: Just force systemd to re-execute itself (2.8 and above)
systemd:
daemon_reexec: yes
- name: run a user service when XDG_RUNTIME_DIR is not set on remote login.
systemd:
name: myservice
state: started
scope: user
environment:
XDG_RUNTIME_DIR: "/run/user/{{ myuid }}"
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
- Ansible Core Team