win_nssm task shows 'changed' for every run

Ubuntu 14.04, Ansible 2.0.0.2

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] ****************

changed: [server1.my.domain.com]

Any way to condition around this?

I’ve not looked at the code, but perhaps it is a bug. Since you seem to be able to reproduce, I suggest raising it in ansible modules extra project (using the issue template) https://github.com/ansible/ansible/raw/devel/ISSUE_TEMPLATE.md

You might be able to work around using changed_when - see http://docs.ansible.com/ansible/playbooks_error_handling.html#controlling-what-defines-failure

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).

Hope this helps,

Jon

Thanks Jon. I’ll see what I can do with these options.

-Joe