Install a service using NSSM
- Install a Windows service using the NSSM wrapper.
- NSSM is a service helper which doesn't suck. See https://nssm.cc/ for more information.
The below requirements are needed on the host that executes this module.
- nssm >= 2.24.0 # (install via :ref:`chocolatey.chocolatey.win_chocolatey <chocolatey.chocolatey.win_chocolatey_module>`)
win_chocolatey: name=nssm
Note
- The service will NOT be started after its creation when
state=present
. - Once the service is created, you can use the :ref:`ansible.windowswin_service <ansible.windowswin_service_module>` module to start it or configure some additionals properties, such as its startup type, dependencies, service account, and so on.
.. seealso:: :ref:`ansible.windows.win_service_module` The official documentation on the **ansible.windows.win_service** module.
- 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
- Adam Keech (@smadam813)
- George Frank (@georgefrank)
- Hans-Joachim Kliemeck (@h0nIg)
- Michael Wild (@themiwi)
- Kevin Subileau (@ksubileau)
- Shachaf Goldstein (@Shachaf92)