ansible.builtin.sysvinit (v2.16.5) — module

Manage SysV services.

| "added in version" 2.6 of ansible.builtin"

Authors: Ansible Core Team

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

Controls services on target hosts that use the SysV init system.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Make sure apache2 is started
  ansible.builtin.sysvinit:
      name: apache2
      state: started
      enabled: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Make sure apache2 is started on runlevels 3 and 5
  ansible.builtin.sysvinit:
      name: apache2
      state: started
      enabled: yes
      runlevels:
        - 3
        - 5

Inputs

    
name:
    aliases:
    - service
    description:
    - Name of the service.
    required: true
    type: str

sleep:
    default: 1
    description:
    - 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.
    type: int

state:
    choices:
    - started
    - stopped
    - restarted
    - reloaded
    description:
    - 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.
    type: str

enabled:
    description:
    - Whether the service should start on boot. B(At least one of state and enabled are
      required.)
    type: bool

pattern:
    description:
    - 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 'status'
      option.
    type: str

arguments:
    aliases:
    - args
    description:
    - Additional arguments provided on the command line that some init scripts accept.
    type: str

daemonize:
    default: false
    description:
    - 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.
    type: bool

runlevels:
    description:
    - The runlevels this script should be enabled/disabled from.
    - Use this to override the defaults set by the package or init script itself.
    elements: str
    type: list

Outputs

results:
  contains:
    name:
      description: Name of the service
      returned: always
      sample: apache2
      type: str
    status:
      description: Status of the service
      returned: changed
      sample:
        enabled:
          changed: true
          rc: 0
          stderr: ''
          stdout: ''
        stopped:
          changed: true
          rc: 0
          stderr: ''
          stdout: 'Stopping web server: apache2.

            '
      type: dict
  description: results from actions taken
  returned: always
  type: complex