community.general.simpleinit_msb 模块 – 在 Source Mage GNU/Linux 上管理服务

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general

要在 playbook 中使用它,请指定:community.general.simpleinit_msb

community.general 7.5.0 中的新增功能

概要

  • 使用 simpleinit-msb 控制远程主机上的服务。

参数

参数

注释

启用

布尔值

该服务是否应在启动时启动。

必须至少指定 stateenabled 中的一个。

选择

  • false

  • true

name

别名:service

字符串 / 必需

服务名称。

state

字符串

started/stopped 是幂等操作,除非必要,否则不会运行命令。restarted 将始终重启服务。reloaded 将始终重新加载。

必须至少指定 stateenabled 中的一个。

请注意,如果服务尚未启动,即使您选择的初始化系统通常不会这样做,reloaded 也会启动该服务。

选择

  • "running"

  • "started"

  • "stopped"

  • "restarted"

  • "reloaded"

属性

属性

支持

描述

check_mode

支持: 完全

可以在 check_mode 中运行,并返回已更改状态预测,而无需修改目标。

diff_mode

支持:

在 diff 模式下,将返回有关已更改(或可能需要在 check_mode 中更改)的详细信息。

备注

注意

  • 此模块需要 ansible-core 2.15.5 或更新版本。较旧的版本具有损坏且不充分的守护进程化功能。

示例

- name: Example action to start service httpd, if not running
  community.general.simpleinit_msb:
    name: httpd
    state: started

- name: Example action to stop service httpd, if running
  community.general.simpleinit_msb:
    name: httpd
    state: stopped

- name: Example action to restart service httpd, in all cases
  community.general.simpleinit_msb:
    name: httpd
    state: restarted

- name: Example action to reload service httpd, in all cases
  community.general.simpleinit_msb:
    name: httpd
    state: reloaded

- name: Example action to enable service httpd, and not touch the running state
  community.general.simpleinit_msb:
    name: httpd
    enabled: true

作者

  • Vlad Glagolev (@vaygr)