community / community.general / 6.6.8 / module / nosh Manage services with nosh Authors: Thomas Caravia (@tacatac)community.general.nosh (6.6.8) — module
Install with ansible-galaxy collection install community.general:==6.6.8
collections: - name: community.general version: 6.6.8
Control running and enabled state for system-wide or user services.
BSD and Linux systems are supported.
- name: Start dnscache if not running community.general.nosh: name: dnscache state: started
- name: Stop mpd, if running community.general.nosh: name: mpd state: stopped
- name: Restart unbound or start it if not already running community.general.nosh: name: unbound state: restarted
- name: Reload fail2ban or start it if not already running community.general.nosh: name: fail2ban state: reloaded
- name: Disable nsd community.general.nosh: name: nsd enabled: false
- 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
- 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
- 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"
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: - C(started)/C(stopped) are idempotent actions that will not run commands unless necessary. C(restarted) will always bounce the service. C(reloaded) will send a SIGHUP or start the service. C(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 I(enabled). Only has an effect if set to true. Will take effect prior to I(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 I(preset). Will take effect prior to I(state=reset). required: false type: bool
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, C(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 C(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