win_nssm – Install a service using NSSM

New in version 2.0.

Synopsis

  • Install a Windows service using the NSSM wrapper.

  • NSSM is a service helper which doesn’t suck. See https://nssm.cc/ for more information.

Requirements

The below requirements are needed on the host that executes this module.

  • nssm >= 2.24.0 # (install via win_chocolatey) win_chocolatey: name=nssm

Parameters

Parameter Choices/Defaults Comments
app_parameters
string
A string representing a dictionary of parameters to be passed to the application when it starts.
DEPRECATED since v2.8, please use arguments instead.
This is mutually exclusive with arguments.
application
path
The application binary to run as a service
Required when state is present, started, stopped, or restarted.
arguments
string
added in 2.3
Parameters to be passed to the application when it starts.
This can be either a simple string or a list.
This parameter was renamed from app_parameters_free_form in 2.8.
This is mutually exclusive with app_parameters.

aliases: app_parameters_free_form
dependencies
list
Service dependencies that has to be started to trigger startup, separated by comma.
DEPRECATED since v2.8, please use the win_service module instead.
description
string
added in 2.8.0
The description to set for the service.
display_name
string
added in 2.8.0
The display name to set for the service.
executable
path
added in 2.8.0
Default:
"nssm.exe"
The location of the NSSM utility (in case it is not located in your PATH).
name
string / required
Name of the service to operate on.
password
string
Password to be used for service startup.
DEPRECATED since v2.8, please use the win_service module instead.
start_mode
string
    Choices:
  • auto ←
  • delayed
  • disabled
  • manual
If auto is selected, the service will start at bootup.
delayed causes a delayed but automatic start after boot (added in version 2.5).
manual means that the service will start only when another service needs it.
disabled means that the service will stay off, regardless if it is needed or not.
DEPRECATED since v2.8, please use the win_service module instead.
state
string
    Choices:
  • absent
  • present ←
  • started
  • stopped
  • restarted
State of the service on the system.
Values started, stopped, and restarted are deprecated since v2.8, please use the win_service module instead to start, stop or restart the service.
stderr_file
path
Path to receive error output.
stdout_file
path
Path to receive output.
user
string
User to be used for service startup.
DEPRECATED since v2.8, please use the win_service module instead.
working_directory
path
added in 2.8.0
The working directory to run the service executable from (defaults to the directory containing the application binary)

aliases: app_directory, chdir

Notes

Note

  • The service will NOT be started after its creation when state=present.

  • Once the service is created, you can use the win_service module to start it or configure some additionals properties, such as its startup type, dependencies, service account, and so on.

See Also

See also

win_service – Manage and query Windows services

The official documentation on the win_service module.

Examples

- name: Install the foo service
  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
  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
  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
  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
  win_service:
    name: foo
    dependencies: [ adf, tcpip ]
    user: foouser
    password: secret
    start_mode: manual
    state: started

- name: Remove the foo service
  win_nssm:
    name: foo
    state: absent

Status

Authors

  • Adam Keech (@smadam813)

  • George Frank (@georgefrank)

  • Hans-Joachim Kliemeck (@h0nIg)

  • Michael Wild (@themiwi)

  • Kevin Subileau (@ksubileau)

Hint

If you notice any issues in this documentation you can edit this document to improve it.