json Packer社区插件 - Windows 2012安装示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json Packer社区插件 - Windows 2012安装示例相关的知识,希望对你有一定的参考价值。
<powershell>
write-output "Running User Data Script"
write-host "(host) Running User Data Script"
cmd.exe /c net user /add vagrant FooBar@123
cmd.exe /c net localgroup administrators vagrant /add
Set-ExecutionPolicy -ExecutionPolicy bypass -Force
# RDP
#cmd.exe /c netsh advfirewall firewall add rule name="Open Port 3389" dir=in action=allow protocol=TCP localport=3389
#cmd.exe /c reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
# WinRM
write-output "Setting up WinRM"
write-host "(host) setting up WinRM"
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm quickconfig '-transport:http'
cmd.exe /c winrm set "winrm/config" '@{MaxTimeoutms="1800000"}'
cmd.exe /c winrm set "winrm/config/winrs" '@{MaxMemoryPerShellMB="1024"}'
cmd.exe /c winrm set "winrm/config/service" '@{AllowUnencrypted="true"}'
cmd.exe /c winrm set "winrm/config/client" '@{AllowUnencrypted="true"}'
cmd.exe /c winrm set "winrm/config/service/auth" '@{Basic="true"}'
cmd.exe /c winrm set "winrm/config/client/auth" '@{Basic="true"}'
cmd.exe /c winrm set "winrm/config/service/auth" '@{CredSSP="true"}'
cmd.exe /c winrm set "winrm/config/listener?Address=*+Transport=HTTP" '@{Port="5985"}'
cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes
cmd.exe /c netsh firewall add portopening TCP 5985 "Port 5985"
cmd.exe /c net stop winrm
cmd.exe /c sc config winrm start= auto
cmd.exe /c net start winrm
cmd.exe /c wmic useraccount where "name='vagrant'" set PasswordExpires=FALSE
</powershell>
{
"builders": [
{
"type": "amazon-windows-ebs",
"region": "ap-southeast-1",
"source_ami": "ami-e01f3db2",
"instance_type": "t2.medium",
"ami_name": "packer-quick-start {{timestamp}}",
"user_data_file":"./scripts/ec2-user-data.ps1",
"associate_public_ip_address":true,
"winrm_username": "vagrant",
"winrm_password": "FooBar@123",
"winrm_wait_timeout": "5m",
"winrm_port":5985,
"vpc_id": "vpc-e141b084",
"subnet_id":"subnet-c774bfa2",
"security_group_id":"sg-a74d86c2",
"tags": {
"Stream":"IT Operations",
"Owner": "Matt Fellows",
"Project":"Project Mario"
}
},
{
"type": "virtualbox-windows-iso",
"iso_url": "/Users/mfellows/Downloads/SW_DVD5_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_Core_MLF_X19-05182.ISO",
"iso_checksum_type": "md5",
"iso_checksum": "83bdf8034bcb019a8f001baeeab27326",
"winrm_username": "vagrant",
"winrm_password": "vagrant",
"winrm_wait_timeout": "5m",
"winrm_port":5985,
"headless": false,
"boot_wait": "2m",
"guest_additions_mode": "disable",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"guest_os_type": "Windows2012_64",
"disk_size": 61440,
"floppy_files": [
"./answer_files/2012_r2/Autounattend.xml",
"./scripts/microsoft-updates.bat",
"./scripts/win-updates.ps1",
"./scripts/oracle-cert.cer"
],
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"2048"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"2"
],
[
"modifyvm",
"{{.Name}}",
"--natpf1",
"guestwinrm,tcp,127.0.0.1,5985,,5985"
]
]
},
{
"type": "virtualbox-windows-ovf",
"source_path": "/Users/mfellows/Downloads/output-virtualbox-iso/packer-virtualbox-iso-1417096689.ovf",
"headless": false,
"guest_additions_mode": "disable",
"boot_wait": "30s",
"winrm_username": "vagrant",
"winrm_password": "vagrant",
"winrm_wait_timeout": "5m",
"winrm_port":5985,
"winrm_host":"localhost",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"http_directory":"/tmp",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"2048"
],
[
"modifyvm",
"{{.Name}}",
"--vram",
"64"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"2"
]
]
}
],
"provisioners": [
{
"type": "powershell",
"elevated_user": "vagrant",
"elevated_password": "vagrant",
"environment_vars":[
"foo=bar",
"bat=bat"
],
"inline": [
"echo $env:foo > c:\\foo.txt",
"echo $env:foo > ~/foo.txt",
"echo 'should have output foo before'",
"echo $env:bat > bat.txt",
"echo $env:bat > ~/bat.txt",
"echo 'should have output bat before'"
]
},
{
"type": "powershell",
"elevated_user": "vagrant",
"elevated_password": "vagrant",
"inline": [
"$wc = New-Object System.Net.WebClient; $wc.DownloadFile(\"http://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu\", \"c:\\wmf4.msu\")",
"c:\\wmf4.msu /quiet"
]
},
{
"pause_before":"300s",
"type":"restart-windows"
},
{
"type": "powershell",
"pause_before":"300s",
"elevated_user": "vagrant",
"elevated_password": "vagrant",
"inline": [
"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
]
},
{
"type":"restart-windows"
},
{
"type": "powershell",
"elevated_user": "vagrant",
"elevated_password": "vagrant",
"environment_vars":[
"foo=bar",
"bat=bat"
],
"inline": [
"choco install netfx-4.5.2-devpack"
]
}
]
}
以上是关于json Packer社区插件 - Windows 2012安装示例的主要内容,如果未能解决你的问题,请参考以下文章
json 在Packer Builder实例上安装Ansible。
Packer 无法验证 jenkins 作业中的 hcl2 模板