ansible.builtin.sysvinit – Manage SysV services.

From Get docs
Ansible/docs/2.10/collections/ansible/builtin/sysvinit module


ansible.builtin.sysvinit – Manage SysV 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 sysvinit 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.6: of ansible.builtin


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 Choices/Defaults Comments

arguments

string

Additional arguments provided on the command line that some init scripts accept.


aliases: args

daemonize

boolean

  • no

  • yes

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

boolean

  • no
  • yes

Whether the service should start on boot. At least one of state and enabled are required.

name

string / required

Name of the service.


aliases: service

pattern

string

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.

runlevels

string

The runlevels this script should be enabled/disabled from.

Use this to override the defaults set by the package or init script itself.

sleep

string

Default:

1

If the service is being restarted or reloaded then sleep this many seconds between the stop and start command. This helps to workaround badly behaving services.

state

string

  • started
  • stopped
  • restarted
  • reloaded

started/stopped are idempotent actions that will not run commands unless necessary. Not all init scripts support restarted nor reloaded natively, so these will both trigger a stop and start as needed.



Notes

Note

  • One option other than name is required.


Examples

- name: Make sure apache2 is started
  sysvinit:
      name: apache2
      state: started
      enabled: yes

- name: Make sure apache2 is started on runlevels 3 and 5
  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 Returned Description

results

complex

always

results from actions taken


Sample:

{'attempts': 1, 'changed': True, 'name': 'apache2', 'status': {'enabled': {'changed': True, 'rc': 0, 'stderr': , 'stdout': }, 'stopped': {'changed': True, 'rc': 0, 'stderr': , 'stdout': 'Stopping web server: apache2.\n'}}}




Authors

  • Ansible Core Team

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.10/collections/ansible/builtin/sysvinit_module.html