I’m using win_nssm to install a service. It’s successfully installing the service, however all subsequent runs show the win_nssm task as ‘changed’.
Why is win_nssm showing ‘changed’ even though the service has already been installed and nothing has been modified? Is it actually re-installing the service?
Playbook:
win_nssm:
name: servicename
state: present
application: C:\path\to\exe
start_mode: manual
user: ********
password: ********
Output:
TASK [appservice : Install appservice via NSSM] ****************
To do so, you might need to check if the service exists already, which you can do something like this (untested)
name: check if service exists
raw: “Get-Service -Name ‘appservice’”
register: appservice_status
ignore_errors: True
Then you’d have to check the stdout stored in the registered appservice_status var to see if it exists.
You could perhaps even use a when: clause so the win_nssm only runs when the service doesn’t exist, although that wouldn’t ever let you reconfigure the service in the same playbook (which may or may not be important to you).