community.windows.win_nssm 模块 – 使用 NSSM 安装服务
注意
此模块是 community.windows 集合 (版本 2.3.0) 的一部分。
如果您使用的是 ansible 包,则您可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.windows。您需要其他要求才能使用此模块,请参阅 要求 获取详细信息。
要在剧本中使用它,请指定:community.windows.win_nssm。
概要
- 使用 NSSM 包装器安装 Windows 服务。 
- NSSM 是一款不错的服务辅助工具。更多信息,请参阅 https://nssm.cc/。 
要求
执行此模块的主机需要以下要求。
- nssm >= 2.24.0 # (通过 chocolatey.chocolatey.win_chocolatey 安装) - win_chocolatey: name=nssm
参数
| 参数 | 注释 | 
|---|---|
| 将添加到服务应用程序环境的键值对。 | |
| NSSM 不会旋转小于配置字节数的任何文件。 默认值:  | |
| 如果设置为 1,则 nssm 可以旋转在服务运行时增长到配置的文件大小限制的文件。 选项 
 | |
| 发送 Control-C 后等待的时间。 | |
| 要禁用服务关闭方法,设置为一个或多个数字的总和 1 - 不要向控制台发送 Control-C。 2 - 不要向窗口发送 WM_CLOSE。 4 - 不要向线程发送 WM_QUIT。 8 - 不要调用 TerminateProcess()。 选项 
 | |
| 要作为服务运行的应用程序二进制文件 当 state 为  | |
| 启动时传递给应用程序的参数。 这可以是简单的字符串或列表。 | |
| 必须启动以触发启动的服务依赖项,用逗号分隔。 | |
| 要为服务设置的描述。 | |
| 要为服务设置的显示名称。 | |
| NSSM 实用程序的位置(如果它不在您的 PATH 中)。 默认值:  | |
| 要操作的服务的名称。 | |
| 用于服务启动的密码。 对于众所周知的服务帐户和组托管的服务帐户,这不是必需的。 | |
| 如果选择  
 
 
 选项 
 | |
| 系统上服务的狀態。 选项 
 | |
| 接收错误输出的路径。 | |
| 接收输出的路径。 | |
| 用于服务启动的用户。 组托管的服务帐户必须以  在  | |
| 运行服务可执行文件的当前工作目录(默认为包含应用程序二进制文件的目录) | 
备注
注意
- 当 - state=present时,服务创建后不会立即启动。
- 服务创建后,您可以使用ansible.windows.win_service模块启动它或配置其他属性,例如启动类型、依赖项、服务帐户等等。 
另请参阅
另请参阅
- ansible.windows.win_service
- 管理和查询 Windows 服务。 
示例
- name: Install the foo service
  community.windows.win_nssm:
    name: foo
    application: C:\windows\foo.exe
# This will yield the following command: C:\windows\foo.exe bar "true"
- name: Install the Consul service with a list of parameters
  community.windows.win_nssm:
    name: Consul
    application: C:\consul\consul.exe
    arguments:
      - agent
      - -config-dir=C:\consul\config
# This is strictly equivalent to the previous example
- name: Install the Consul service with an arbitrary string of parameters
  community.windows.win_nssm:
    name: Consul
    application: C:\consul\consul.exe
    arguments: agent -config-dir=C:\consul\config
# Install the foo service, and then configure and start it with win_service
- name: Install the foo service, redirecting stdout and stderr to the same file
  community.windows.win_nssm:
    name: foo
    application: C:\windows\foo.exe
    stdout_file: C:\windows\foo.log
    stderr_file: C:\windows\foo.log
- name: Configure and start the foo service using win_service
  ansible.windows.win_service:
    name: foo
    dependencies: [adf, tcpip]
    username: foouser
    password: secret
    start_mode: manual
    state: started
- name: Install a script based service and define custom environment variables
  community.windows.win_nssm:
    name: <ServiceName>
    application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    arguments:
      - <path-to-script>
      - <script arg>
    app_environment:
      AUTH_TOKEN: <token value>
      SERVER_URL: https://example.com
      PATH: "<path-prepends>;{{ ansible_env.PATH }};<path-appends>"
- name: Remove the foo service
  community.windows.win_nssm:
    name: foo
    state: absent
