ansible.builtin.sysvinit module – Manage SysV services.
Note
This module is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
module name
sysvinit
even without specifying the collections keyword.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.sysvinit
for easy linking to the
module documentation and to avoid conflicting with other collections that may have
the same module name.
Synopsis
Controls services on target hosts that use the SysV init system.
Requirements
The below requirements are needed on the host that executes this module.
That the service managed has a corresponding init script.
Parameters
Parameter |
Comments |
---|---|
Additional arguments provided on the command line that some init scripts accept. |
|
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. Choices:
|
|
Whether the service should start on boot. At least one of state and enabled are required. Choices:
|
|
Name of the service. |
|
A substring to look for as would be found in the output of the 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 ‘status’ option. |
|
The runlevels this script should be enabled/disabled from. Use this to override the defaults set by the package or init script itself. |
|
If the service is being Default: |
|
Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in check_mode and return changed status prediction without modifying target, if not supported the action will be skipped. |
|
Support: none |
Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode |
|
Platform: posix |
Target OS/families that can be operated against |
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
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
results from actions taken Returned: always |
|
Name of the service Returned: always Sample: |
|
Status of the service Returned: changed Sample: |