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