Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 873
Nico Avatar asked Jan 09 '15 14:01

Nico


People also ask

Can you use Ansible with Windows?

Can Ansible run on Windows?  No, Ansible can only manage Windows hosts. Ansible cannot run on a Windows host natively, though it can run under the Windows Subsystem for Linux (WSL).

How do I run Ansible batch file in Windows?

Save the script (the batch file) on the control server. Ansible copies the script to the remote host and then execute it there. See example below — it is assumed that run. bat file is saved in /tmp (not a best practice) directory on your control server.


1 Answers

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 the win_stat module and the when 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:

- name: Check to see if MSBuild is installed
  win_stat: path='C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe'
  register: msbuild_installed
- name: Download MS Build Tools 2013
  win_get_url:
    url: 'http://download.microsoft.com/download/9/B/B/9BB1309E-1A8F-4A47-72A3B3/BuildTools_Full.exe'
    dest: 'c:\temp\BuildTools_Full.exe'
  when: not msbuild_installed.stat.exists
- name: Install MS Build Tools 2013
  raw: 'c:\temp\BuildTools_Full.exe /Quiet /NoRestart /Full'
  when: not msbuild_installed.stat.exists

Note that I found the command line arguments for BuildTools_Full.exe by manually running

.\BuildTools_Full.exe /h
like image 121
sfuqua Avatar answered Oct 10 '22 23:10

sfuqua