community.general.launchd (8.5.0) — module

Manage macOS services

| "added in version" 1.0.0 of community.general"

Authors: Martin Migasiewicz (@martinm82)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Manage launchd services on target macOS hosts.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Make sure spotify webhelper is started
  community.general.launchd:
    name: com.spotify.webhelper
    state: started
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Deploy custom memcached job definition
  template:
    src: org.memcached.plist.j2
    dest: /Library/LaunchDaemons/org.memcached.plist
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run memcached
  community.general.launchd:
    name: org.memcached
    state: started
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Stop memcached
  community.general.launchd:
    name: org.memcached
    state: stopped
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Stop memcached
  community.general.launchd:
    name: org.memcached
    state: stopped
    force_stop: true
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Restart memcached
  community.general.launchd:
    name: org.memcached
    state: restarted
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Unload memcached
  community.general.launchd:
    name: org.memcached
    state: unloaded

Inputs

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

state:
    choices:
    - reloaded
    - restarted
    - started
    - stopped
    - unloaded
    description:
    - V(started)/V(stopped) are idempotent actions that will not run commands unless necessary.
    - Launchd does not support V(restarted) nor V(reloaded) natively. These will trigger
      a stop/start (restarted) or an unload/load (reloaded).
    - V(restarted) unloads and loads the service before start to ensure that the latest
      job definition (plist) is used.
    - V(reloaded) unloads and loads the service to ensure that the latest job definition
      (plist) is used. Whether a service is started or stopped depends on the content
      of the definition file.
    type: str

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

force_stop:
    default: false
    description:
    - Whether the service should not be restarted automatically by launchd.
    - Services might have the 'KeepAlive' attribute set to true in a launchd configuration.
      In case this is set to true, stopping a service will cause that launchd starts the
      service again.
    - Set this option to V(true) to let this module change the 'KeepAlive' attribute to
      V(false).
    type: bool

Outputs

status:
  description: Metadata about service status
  returned: always
  sample:
    current_pid: '-'
    current_state: stopped
    previous_pid: '82636'
    previous_state: running
  type: dict