Ansible module to run window service

Hello, I’m very new to Ansible.

I noticed that there is a win_service module to create window service but none to run a window service. I have a powershell script to do that. Is it better to create a new module or integrate this function ( running windows service) with the existing win_service module?

Thanks in advance!

Hi

Generally I would say creating modules is well worth it, however you might not need to in this case.

win_service is actually just for controlling whether an existing service is started or stopped, (or restarted).

If you need to make a .exe run as a windows service there is the win_nssm module. You have to install nssm (which is easy as its just a small exe file you can put in place using win_copy), then you can use win_nssm to create the service.

Hope this helps,

Jon

Thank you! That is very helpful! According to the win_nssm document, it should be install using win_chocolatey, I wonder if you meant the same thing? Would you care to elaborate more about the install nssm part? Thank you so much for your help.

在 2016年7月25日星期一 UTC-4上午6:09:08,jhawkesworth写道:

win_chocolatey is a convenient way to install nssm but it is quite small so you can probably download straight from the nssm website using win_get_url

https://nssm.cc/release/nssm-2.24.zip

Then use win_unzip to unzip it somewhere. If I remember there is 32bit and 64bit version in the zip file.

Hope this helps.

Jon

By the way, questions like this are probably best asked on ansible-project group or ansible irc channel as there are more ansible users there (this group is for ansible developers).

Thank you! So I wrote following task:

  • name: install win_nssm
    win_chocolatey:
    name: nssm

  • name: create and run service name service
    win_nssm:
    name: servicename
    application: path
    start_mode: auto

The service is created but not started( service status is blank ). I was able to start it manually (Hit the start button in windows services console) though. Then I tried to add another task:

  • name: run servicename
    win_service:
    name: servicename
    start_mode: auto
    state: started

Then the service status is ‘Paused’ and I can’t even started it manually.

As I understand, win_nssm suppose to not only create the service but also start the service correct? Am I using the module wrong?

Thank you so much for your help!

在 2016年7月26日星期二 UTC-4上午9:18:56,jhawkesworth写道:

I think if you add state: started to your win_nssm module parameters that should be enough to get it to start without the need to add win_service module to your playbook.

If the service is paused, though, its possible the program you are trying to run as a service is trying to do something it doesn’t have permission to do. For example recent versions of Windows do not allow services to display user interfaces by default. If that applies there are some workarounds described here: http://www.slideshare.net/jhawkesworth/ansible-20-windows-and-no-powershell-this-year-i-promise-ansiblefest-london-2016

Its possible other things are not correct, such as the user that the service is running as - I think you will have to debug why the service enters the paused state.

Hope this helps,

Jon