Packer 无法与 AWS windows 服务器 2016 实例通信以构建自定义 ami

Packer cannot communicate with AWS windows server 2016 instances to build custom ami

我正在使用 packer 0.12.1 构建基于现有 windows 服务器 2016 ami 的 AWS ami。

我用来让它与 windows server 2012 一起工作的方法是在加壳模板中指定:

"communicator": "winrm",
"winrm_username": "Administrator",
"winrm_use_ssl": true,
"winrm_insecure": true,
"user_data_file":"./ec2-userdata-winserver2016.ps1",

用户数据文件如下所示:

<powershell>

write-output "Running User Data Script"
write-host "(host) Running User Data Script"

Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore

# Don't set this before Set-ExecutionPolicy as it throws an error
$ErrorActionPreference = "stop"

# Remove HTTP listener
Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse

$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer"
New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force

# WinRM
write-output "Setting up WinRM"
write-host "(host) setting up WinRM"

cmd.exe /c winrm quickconfig -q
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=HTTPS" "@{Port=`"5986`";Hostname=`"packer`";CertificateThumbprint=`"$($Cert.Thumbprint)`"}"
cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes
cmd.exe /c netsh firewall add portopening TCP 5986 "Port 5986"
cmd.exe /c net stop winrm
cmd.exe /c sc config winrm start= auto
cmd.exe /c net start winrm

</powershell>

这在 windows 服务器 2012 中工作正常,但在 windows 服务器 2016 中不再有效。

对于server 2016,packer的输出是:

==> eu-west-1-builder: Waiting for auto-generated password for instance...
    eu-west-1-builder: It is normal for this process to take up to 15 minutes,
    eu-west-1-builder: but it usually takes around 5. Please wait.
    eu-west-1-builder:  
    eu-west-1-builder: Password retrieved!
==> eu-west-1-builder: Waiting for WinRM to become available...

它挂起直到超时。

由于 AWS 最近发布了 windows server 2016 ami,我找不到太多信息。我不是真正的 windows 大师(我通常在 linux)

如有任何帮助/建议,我们将不胜感激。

尝试将 "winrm_username" 更改为 Administrator

以外的内容

根据 Packer documentation默认用户名是 packer 而不是 root,就像在其他构建器中一样。 Azure 上的大多数发行版不允许 root 通过 SSH 连接到 VM,因此需要非 root 默认用户。设置 ssh_username 选项以覆盖默认值。