使用Ansible在Windows上执行.exe

Nic*_*ico 7 windows ansible

我们希望在带有Ansible 1.8.2的Windows Server 2012上部署应用程序.

我搜索并找到 Windows的模块列表.是否有一个模块来执行.exe?

有人已经在Windows上使用Ansible启动了.exe吗?

viv*_*ivo 7

文档说"请注意,还有一些其他Ansible模块不以"win"开头也起作用,包括"slurp","raw"和"setup"(事实收集的工作方式).(http://docs.ansible.com/intro_windows.html),所以我认为'raw'模块(http://docs.ansible.com/raw_module.html)应该可以工作(我目前没有Windows VM)可以玩):

所以请尝试一下剧本:

- raw: <your .exe>
Run Code Online (Sandbox Code Playgroud)

或者是一个Ansible adhoc命令:

 ansible <your server> -m raw -a '<your .exe>'
Run Code Online (Sandbox Code Playgroud)


sfu*_*qua 5

raw正如其他人所建议的那样,该模块可以工作.一个挑战是它不会"知道"以前是否已经运行过可执行文件.结合win_stat模块和when条件,您可以构建一个脚本来检测是否已安装某些内容并在未安装时运行.例如,我想安装MSBuild开发工具:

- 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
Run Code Online (Sandbox Code Playgroud)

请注意,我通过手动运行找到了BuildTools_Full.exe的命令行参数

.\BuildTools_Full.exe /h
Run Code Online (Sandbox Code Playgroud)