sysvinit¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.6.
You need further requirements to be able to use this module, see the Requirements section for details.
Synopsis¶
- Controls services on target hosts that use the SysV init system.
Requirements¶
The following Python packages are needed on the host that executes this module:
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| arguments str |
Additional arguments provided on the command line that some init scripts accept. | |
| daemonize bool |
Have the module daemonize as the service itself might not do so properly. This is useful with badly written init scripts or daemons, which commonly manifests as the task hanging as it is still holding the tty or the service dying when the task is over as the connection closes the session. |
|
| enabled bool |
Whether the service should start on boot. At least one of O(state) and O(enabled) are required. | |
| name str required |
Name of the service. | |
| pattern str |
A substring to look for as would be found in the output of the I(ps) command as a stand-in for a status result. If the string is found, the service will be assumed to be running. This option is mainly for use with init scripts that don't support the C(status) option. |
|
| runlevels list / elements=str |
The runlevels this script should be enabled/disabled from. Use this to override the defaults set by the package or init script itself. |
|
| sleep int |
Default: 1 |
If the service is being V(restarted) or V(reloaded) then sleep this many seconds between the stop and start command. This helps to workaround badly behaving services. |
| state str |
Choices: started, stopped, restarted, reloaded | V(started)/V(stopped) are idempotent actions that will not run commands unless necessary. Not all init scripts support V(restarted) nor V(reloaded) natively, so these will both trigger a stop and start as needed. |
Notes¶
Note
- One option other than name is required.
- The service names might vary by specific OS/distribution.
Examples¶
- name: Make sure apache2 is started
ansible.builtin.sysvinit:
name: apache2
state: started
enabled: yes
- name: Sleep for 5 seconds between stop and start command of badly behaving service
ansible.builtin.sysvinit:
name: apache2
state: restarted
sleep: 5
- name: Make sure apache2 is started on runlevels 3 and 5
ansible.builtin.sysvinit:
name: apache2
state: started
enabled: yes
runlevels:
- 3
- 5
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| results | complex | results from actions taken | always |
Authors¶
- Ansible Core Team