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
.Supports
check_mode
.
Examples¶
- name: Make sure a service is running
ansible.builtin.systemd:
state: started
name: httpd
- name: Stop service cron on debian, if running
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:
state: restarted
daemon_reload: yes
name: crond
- name: Reload service httpd, in all cases
ansible.builtin.systemd:
name: httpd
state: reloaded
- name: Enable service httpd and ensure it is not masked
ansible.builtin.systemd:
name: httpd
enabled: yes
masked: no
- name: Enable a timer for dnf-automatic
ansible.builtin.systemd:
name: dnf-automatic.timer
state: started
enabled: yes
- name: Just force systemd to reread configs (2.4 and above)
ansible.builtin.systemd:
daemon_reload: yes
- name: Just force systemd to re-execute itself (2.8 and above)
ansible.builtin.systemd:
daemon_reexec: yes
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Ansible Core Team