We want to deploy an application on a Windows Server 2012 with Ansible 1.8.2.
I have searched and found a list of modules for Windows. Is there a module to execute a .exe?
Did someone already launch a .exe on Windows with Ansible?
We want to deploy an application on a Windows Server 2012 with Ansible 1.8.2.
I have searched and found a list of modules for Windows. Is there a module to execute a .exe?
Did someone already launch a .exe on Windows with Ansible?
As mentioned here, you can use
win_command
. But if you need to run an interactive .exe, you may need to run it through PsExec. An example Playbook can then look like this:The
raw
module can work, as others have suggested. One challenge is that it won't "know" if the executable has already been run before. In combination with thewin_stat
module and thewhen
conditional, you can build a script that detects if something has been installed and runs if not installed. For example, I wanted to install the MSBuild development tools:Note that I found the command line arguments for BuildTools_Full.exe by manually running
There´s another way (and modules) which is not so obvious in the first place: the win_service module combined with the win_nssm module.
As sfuqua already mentioned, most of the time you want to know the "state" of your application - e.g. if it was already installed, is currently running, stopped and so on. Therefore the concept of a Windows service is a very good solution. And it´s very easy to get such a service through the usage of the Non-Sucking Service Manager (nssm).
With the Ansible win_nssm module that´s a cakewalk:
Now we have a real Windows service and can manipulate the state with the help of the win_service module, just as we are used to from applications running on Linux:
This approach frees us of the need to use the raw module (which has some disadvantages, like disabling change handler support) and the troubles to write and maintain scripts for this simple task.
I have resolved the issue with psexec
In the Playbook
And startProcess.ps1
You need to install the psexec in the remote PC. Switches for the psexec
The documentation says 'Note there are a few other Ansible modules that don’t start with “win” that also function, including “slurp”, “raw”, and “setup” (which is how fact gathering works).' (http://docs.ansible.com/intro_windows.html), so I would assume that the 'raw' module (http://docs.ansible.com/raw_module.html) should work (I have no Windows VM currently available to play around):
So please try a playbook with:
or an Ansible adhoc command: