Service

Handle packages on Debian-based distributions (Debian, Ubuntu, Linux Mint, Kali, Raspberry Pi OS...)

Parameters

ParameterTypeValueDescription
nameString<service-name>Name of the service to handle
stateStringstarted|stoppedExpected state of the service
enabledBooltrue|falseIs the service expected to be enabled ?

Examples

---
- name: Handle services on the host
  steps:
    - name: Start a service
      with_sudo: true
      service:
        name: apache2
        state: started

    - name: Stop a service
      with_sudo: true
      service:
        name: apache2
        state: started

    - name: Start and enable a service
      with_sudo: true
      service:
        name: apache2
        state: started
        enabled: true

    - name: Disable a service (without stopping it)
      with_sudo: true
      service:
        name: apache2
        enabled: false