ansible / ansible.builtin / v2.7.10 / module / nosh Manage services with nosh | "added in version" 2.5 of ansible.builtin" Authors: Thomas Caravia preview | supported by communityansible.builtin.nosh (v2.7.10) — module
pip
Install with pip install ansible==2.7.10
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: boolean name: description: name used to find the service returned: success sample: sshd type: string preset: description: whether the enabled status reflects the one set in the relevant C(*.preset) file returned: success sample: false type: boolean service_path: description: resolved path for the service returned: success sample: /var/sv/sshd type: string 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: string status: contains: After: - /etc/service-bundles/targets/basic - ../sshdgenkeys - log Before: - /etc/service-bundles/targets/shutdown Conflicts: [] DaemontoolsEncoreState: running DaemontoolsState: up Enabled: true LogService: ../cyclog@sshd MainPID: 661 Paused: false ReadyAfterRun: false RemainAfterExit: false Required-By: [] RestartExitStatusCode: 0 RestartExitStatusNumber: 0 RestartTimestamp: 4611686019935648081 RestartUTCTimestamp: 1508260140 RunExitStatusCode: 0 RunExitStatusNumber: 0 RunTimestamp: 4611686019935648081 RunUTCTimestamp: 1508260140 StartExitStatusCode: 1 StartExitStatusNumber: 0 StartTimestamp: 4611686019935648081 StartUTCTimestamp: 1508260140 StopExitStatusCode: 0 StopExitStatusNumber: 0 StopTimestamp: 4611686019935648081 StopUTCTimestamp: 1508260140 Stopped-By: - /etc/service-bundles/targets/shutdown Timestamp: 4611686019935648081 UTCTimestamp: 1508260140 Want: nothing Wanted-By: - /etc/service-bundles/targets/server - /etc/service-bundles/targets/sockets Wants: - /etc/service-bundles/targets/basic - ../sshdgenkeys 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: boolean