ansible远程在Windows server 2012 R2 安装vcredist(2008 2010 2012 2013)
需求:
远程在windows server 2012 R2上安装vcredist 2008, 2010, 2012和2013 四个版本。
首先在ansible的官方文档找了一下看有没有适合的模块直接能使用的。
最开始找到的是win_package模块: http://docs.ansible.com/ansible/win_package_module.html ,同时看到它给出来的例子.
感觉可以直接拿来就用啊。把path路径换成要安装的exe 放置的本地路径,不就可以了吗?
后来发现,win_package里的product_id 是必须的,但是在系统没有安装vcredist之前,这些product_id 是获取不到的。尝试了先在系统手动安装四个vcredist 版本,然后再去注册表找到product_id。然后再将product_id 写到ansible-playbook里,没错,最后还是失败了。
好吧,只能找其他办法了,尝试使用powershell脚本实现。
刚开始,测试安装vcredits2008 的脚本是这样的:
vcredist_2008.ps1
$pathvargs_2008 = {C:\tmp\vcredist2008_x64.exe /S /v/qn }
Invoke-Command -ScriptBlock $pathvargs_2008
然后ansible-playbook脚本是这样的:
win_shell.yml :
--- - name: run win_shell hosts: ec2_windows gather_facts: false tasks: - name: Install 2008 ... win_shell: c:\tmp\vcredist_2008.ps1ansible-playbook win_shell.yml 执行一下,发现居然成功了。
依样画葫芦,咔咔咔,就把其他三个版本的脚本,换了个安装包的名字,就以为可以了。
后来,发现vcredist2010的版本总是安装不上。手动安装比较了一下,软件在安装的时候,2010提示的信息和其余三个版本的有点差异,应该在powershell脚本的参数上是不一样的。
好吧,继续在网上找原因。
终于找到了一篇有用的文章:《Mailbag: How to perform a silent install of the Visual C++ 2010 redistributable packages》https://blogs.msdn.microsoft.com/astebner/2010/10/20/mailbag-how-to-perform-a-silent-install-of-the-visual-c-2010-redistributable-packages/
原来在微软的官网上一直躺着我要找的答案。文章里提到了Silent install, Unattended install, Silent repair, Silent uninstall. 四种方式,我现在要找的就是Unattended install模式,不需要人工交互的方式。马上将参数复制黏贴过来使用。
所以,现在的vcredist_2010.ps1 的命令变成了这样:
$pathvargs_2010 = {C:\tmp\vcredist2010_x64.exe /passive /norestart }
Invoke-Command -ScriptBlock $pathvargs_2010
就是2010 版本安装的脚本不一样而已,其他的都一样。
最终的ansible-playbook 是这样的:
vim win_shell.yml :
---
- name: run win_shell
hosts: ec2_windows
gather_facts: false
tasks:
- name: Install 2013 ...
win_shell: c:\tmp\vcredist_2013.ps1
- name: Install 2008 ...
win_shell: c:\tmp\vcredist_2008.ps1
- name: Install 2012
win_shell: c:\tmp\vcredist_2012.ps1
- name: Install 2010 ...
win_shell: c:\tmp\vcredist_2010.ps1
测试:
先把服务器上之前安装的vcredist都卸载了,再运行 ansible-playbook win_shell.yml 。
我就静静地等待结果,最终看到四个成功的提示。然后,在server 2012 R2 服务器上,查看注册表,四个版本的vcredist 都成功安装了。
vCenter 6.5U1 Windows SQL Server 2012 安装vcenter server 7.0安装
Windows Server2012 R2安装VC 6.5使用自建的sql server 2012windows server 2012 r2安装数据库
VMWare之——安装Windows Server 2012 后安装VMWare Tools报错server2012安装vmware报错
windows 2012 r2 standard 安装vcredist
Windows系统因“CredSSP加密Oracle修正”无法远程连接远程桌面credssp加密oracle修正
Windows Server 2012 R2 Shutting down service:Windows Modules Installer 卡住windows server 2012 r2系统
安装VMware workstation以及创建windows server 2012 R2在vmware上安装windows server 2012
How to Uninstall (or Reinstall) Windows 10’s Ubuntu Bash Shellplease uninstall and reinstall the