community / community.general / 0.1.1 / module / nosh Manage services with nosh Authors: Thomas Caravia (@tacatac) preview | supported by communitycommunity.general.nosh (0.1.1) — module
Install with ansible-galaxy collection install community.general:==0.1.1
collections: - name: community.general version: 0.1.1
Control running and enabled state for system-wide or user services.
BSD and Linux systems are supported.
- name: start dnscache if not running nosh: name=dnscache state=started
- name: stop mpd, if running nosh: name=mpd state=stopped
- name: restart unbound or start it if not already running nosh: name: unbound state: restarted
- name: reload fail2ban or start it if not already running nosh: name: fail2ban state: reloaded
- name: disable nsd nosh: name=nsd enabled=no
- name: for package installers, set nginx running state according to local enable settings, preset and reset 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 nosh: name=reboot state=started
- name: using conditionals with the module facts tasks: - name: obtain information on tinydns service nosh: name=tinydns register: result - name: fail if service not loaded fail: msg="The {{ result.name }} service is not loaded" when: not result.status - name: fail if service is running 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 user: default: 'no' 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 preset: description: - Enable or disable the service according to local preferences in *.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: returned: success sample: - /etc/service-bundles/targets/basic - ../sshdgenkeys - log type: list Before: returned: success sample: - /etc/service-bundles/targets/shutdown type: list Conflicts: returned: success sample: '[]' type: list DaemontoolsEncoreState: returned: success sample: running type: str DaemontoolsState: returned: success sample: up type: str Enabled: returned: success sample: true type: bool LogService: returned: success sample: ../cyclog@sshd type: str MainPID: returned: success sample: 661 type: int Paused: returned: success sample: 'False' type: bool ReadyAfterRun: returned: success sample: 'False' type: bool RemainAfterExit: returned: success sample: 'False' type: bool Required-By: returned: success sample: '[]' type: list RestartExitStatusCode: returned: success sample: '0' type: int RestartExitStatusNumber: returned: success sample: '0' type: int RestartTimestamp: returned: success sample: 4611686019935648081 type: int RestartUTCTimestamp: returned: success sample: 1508260140 type: int RunExitStatusCode: returned: success sample: '0' type: int RunExitStatusNumber: returned: success sample: '0' type: int RunTimestamp: returned: success sample: 4611686019935648081 type: int RunUTCTimestamp: returned: success sample: 1508260140 type: int StartExitStatusCode: returned: success sample: 1 type: int StartExitStatusNumber: returned: success sample: '0' type: int StartTimestamp: returned: success sample: 4611686019935648081 type: int StartUTCTimestamp: returned: success sample: 1508260140 type: int StopExitStatusCode: returned: success sample: '0' type: int StopExitStatusNumber: returned: success sample: '0' type: int StopTimestamp: returned: success sample: 4611686019935648081 type: int StopUTCTimestamp: returned: success sample: 1508260140 type: int Stopped-By: returned: success sample: - /etc/service-bundles/targets/shutdown type: list Timestamp: returned: success sample: 4611686019935648081 type: int UTCTimestamp: returned: success sample: 1508260140 type: int Want: returned: success sample: nothing type: str Wanted-By: returned: success sample: - /etc/service-bundles/targets/server - /etc/service-bundles/targets/sockets type: list Wants: returned: success sample: - /etc/service-bundles/targets/basic - ../sshdgenkeys type: list description: a dictionary with the key=value pairs returned by `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