我们希望使用Ansible 1.8.2在Windows Server 2012上部署应用程序。
我已经搜索并找到了一个针对Windows的模块列表(链接)。是否有一个可以执行.exe文件的模块?
是否已有人在Windows上使用Ansible运行过.exe文件?
我已经搜索并找到了一个针对Windows的模块列表(链接)。是否有一个可以执行.exe文件的模块?
是否已有人在Windows上使用Ansible运行过.exe文件?
- 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
.\BuildTools_Full.exe /h
- raw: <your .exe>
ansible <your server> -m raw -a '<your .exe>'
win_command
。但如果您需要运行一个交互式的.exe文件,则可能需要通过PsExec来运行它。然后,示例Playbook可能如下所示: - name: Test PsExec
hosts: windows
tasks:
- name: Copy PsExec
win_copy:
src: <WORKING_FOLDER>/PsExec.exe
dest: "{{ ansible_user_dir }}/Desktop/PsExec.exe"
force: no
- name: Run Windows Calculator
win_command: "{{ ansible_user_dir }}/Desktop/psexec.exe -accepteula -nobanner -i 1 -s calc.exe"
register: output
- debug: var=output
- name: Install & start application as Windows service (via nssm)
win_nssm:
name: "your_app_name"
application: "{{path_to_your_apps_exe}}"
state: restarted
- name: Control app Windows service
win_service:
name: "your_app_name"
state: stopped
我已经解决了与psexec有关的问题。
在Playbook中。
- name: test raw module
hosts: Windows
gather_facts: false
tasks:
- name: Stop process 01
script: startProcess.ps1
而 startProcess.ps1
#Creating the credential for the invoke-command.
$strScriptUser = "COMPUTERNAME\USer"
$strPass = "PASSWORD"
$PSS = ConvertTo-SecureString $strPass -AsPlainText -Force
$cred = new-object system.management.automation.PSCredential $strScriptUser,$PSS
#Invoke-Command to call the psexec to start the application.
invoke-command -Computer "." -Scriptblock {
c:\AnsibleTest\ps\psexec.exe -accepteula -d -h -i 1 -u COMPUTERNAME\USER -p PASSWORD PATH_TO_THE_EXE\PROGRAM.EXE
} -Credential $cred
您需要在远程计算机上安装psexec。psexec的开关