community.general.nosh (8.5.0) — module

Manage services with nosh

Authors: Thomas Caravia (@tacatac)

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

Control running and enabled state for system-wide or user services.

BSD and Linux systems are supported.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Start dnscache if not running
  community.general.nosh:
    name: dnscache
    state: started
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Stop mpd, if running
  community.general.nosh:
    name: mpd
    state: stopped
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Restart unbound or start it if not already running
  community.general.nosh:
    name: unbound
    state: restarted
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reload fail2ban or start it if not already running
  community.general.nosh:
    name: fail2ban
    state: reloaded
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable nsd
  community.general.nosh:
    name: nsd
    enabled: false
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: For package installers, set nginx running state according to local enable settings, preset and reset
  community.general.nosh:
    name: nginx
    preset: true
    state: reset
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reboot the host if nosh is the system manager, would need a "wait_for*" task at least, not recommended as-is
  community.general.nosh:
    name: reboot
    state: started
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Using conditionals with the module facts
  tasks:
    - name: Obtain information on tinydns service
      community.general.nosh:
        name: tinydns
      register: result

    - name: Fail if service not loaded
      ansible.builtin.fail:
        msg: "The {{ result.name }} service is not loaded"
      when: not result.status

    - name: Fail if service is running
      ansible.builtin.fail:
        msg: "The {{ result.name }} service is running"
      when: result.status and result.status['DaemontoolsEncoreState'] == "running"

Inputs

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

user:
    default: false
    description:
    - Run system-control talking to the calling user's service manager, rather than the
      system-wide service manager.
    required: false
    type: bool

state:
    choices:
    - started
    - stopped
    - reset
    - restarted
    - reloaded
    description:
    - V(started)/V(stopped) are idempotent actions that will not run commands unless necessary.
      V(restarted) will always bounce the service. V(reloaded) will send a SIGHUP or start
      the service. V(reset) will start or stop the service according to whether it is
      enabled or not.
    required: false
    type: str

preset:
    description:
    - Enable or disable the service according to local preferences in C(*.preset) files.
      Mutually exclusive with O(enabled). Only has an effect if set to true. Will take
      effect prior to O(state=reset).
    required: false
    type: bool

enabled:
    description:
    - Enable or disable the service, independently of C(*.preset) file preference or running
      state. Mutually exclusive with O(preset). Will take effect prior to O(state=reset).
    required: false
    type: bool

Outputs

enabled:
  description: whether the service is enabled at system bootstrap
  returned: success
  sample: true
  type: bool
name:
  description: name used to find the service
  returned: success
  sample: sshd
  type: str
preset:
  description: whether the enabled status reflects the one set in the relevant C(*.preset)
    file
  returned: success
  sample: 'False'
  type: bool
service_path:
  description: resolved path for the service
  returned: success
  sample: /var/sv/sshd
  type: str
state:
  description: service process run state, V(none) if the service is not loaded and
    will not be started
  returned: if state option is used
  sample: reloaded
  type: str
status:
  contains:
    After:
      description: []
      returned: success
      sample:
      - /etc/service-bundles/targets/basic
      - ../sshdgenkeys
      - log
      type: list
    Before:
      description: []
      returned: success
      sample:
      - /etc/service-bundles/targets/shutdown
      type: list
    Conflicts:
      description: []
      returned: success
      sample: []
      type: list
    DaemontoolsEncoreState:
      description: []
      returned: success
      sample: running
      type: str
    DaemontoolsState:
      description: []
      returned: success
      sample: up
      type: str
    Enabled:
      description: []
      returned: success
      sample: true
      type: bool
    LogService:
      description: []
      returned: success
      sample: ../cyclog@sshd
      type: str
    MainPID:
      description: []
      returned: success
      sample: 661
      type: int
    Paused:
      description: []
      returned: success
      sample: 'False'
      type: bool
    ReadyAfterRun:
      description: []
      returned: success
      sample: 'False'
      type: bool
    RemainAfterExit:
      description: []
      returned: success
      sample: 'False'
      type: bool
    Required-By:
      description: []
      returned: success
      sample: []
      type: list
    RestartExitStatusCode:
      description: []
      returned: success
      sample: '0'
      type: int
    RestartExitStatusNumber:
      description: []
      returned: success
      sample: '0'
      type: int
    RestartTimestamp:
      description: []
      returned: success
      sample: 4611686019935648081
      type: int
    RestartUTCTimestamp:
      description: []
      returned: success
      sample: 1508260140
      type: int
    RunExitStatusCode:
      description: []
      returned: success
      sample: '0'
      type: int
    RunExitStatusNumber:
      description: []
      returned: success
      sample: '0'
      type: int
    RunTimestamp:
      description: []
      returned: success
      sample: 4611686019935648081
      type: int
    RunUTCTimestamp:
      description: []
      returned: success
      sample: 1508260140
      type: int
    StartExitStatusCode:
      description: []
      returned: success
      sample: 1
      type: int
    StartExitStatusNumber:
      description: []
      returned: success
      sample: '0'
      type: int
    StartTimestamp:
      description: []
      returned: success
      sample: 4611686019935648081
      type: int
    StartUTCTimestamp:
      description: []
      returned: success
      sample: 1508260140
      type: int
    StopExitStatusCode:
      description: []
      returned: success
      sample: '0'
      type: int
    StopExitStatusNumber:
      description: []
      returned: success
      sample: '0'
      type: int
    StopTimestamp:
      description: []
      returned: success
      sample: 4611686019935648081
      type: int
    StopUTCTimestamp:
      description: []
      returned: success
      sample: 1508260140
      type: int
    Stopped-By:
      description: []
      returned: success
      sample:
      - /etc/service-bundles/targets/shutdown
      type: list
    Timestamp:
      description: []
      returned: success
      sample: 4611686019935648081
      type: int
    UTCTimestamp:
      description: []
      returned: success
      sample: 1508260140
      type: int
    Want:
      description: []
      returned: success
      sample: nothing
      type: str
    Wanted-By:
      description: []
      returned: success
      sample:
      - /etc/service-bundles/targets/server
      - /etc/service-bundles/targets/sockets
      type: list
    Wants:
      description: []
      returned: success
      sample:
      - /etc/service-bundles/targets/basic
      - ../sshdgenkeys
      type: list
  description: A dictionary with the key=value pairs returned by C(system-control
    show-json) or V(none) if the service is not loaded
  returned: success
  type: complex
user:
  description: whether the user-level service manager is called
  returned: success
  sample: false
  type: bool