This works for me building W2016 Servers, YMMV...

Here is my build file:
{
    "builders": [{
        "type":             "amazon-ebs",
        "vpc_id":           "**********",
        "subnet_id":        "**********",
        "region":           "us-east-1",
        "source_ami":       "**********",
        "ami_name":         "My packer-demo-{{timestamp}}",
        "user_data_file":   "*./USERDATA2.0.txt*",
        "communicator":     "winrm",
        "winrm_username":   "Administrator",
        "instance_type":    "m3.medium",
        "winrm_use_ssl":    true,
        "winrm_insecure":   true
    }],

    "provisioners": [
        {
            "type":         "file",
            "source":       "./packages/something/",
            "destination":  "C:\\temp"
        },        
        {
            "type":         "powershell",
            "script":       "./install_something.ps1"      
        },
        {
            "type":         "powershell",
            "inline": [
                
"C:/ProgramData/Amazon/EC2-Windows/Launch/Scripts/InitializeInstance.ps1 
-Schedule"
,
                
"C:/ProgramData/Amazon/EC2-Windows/Launch/Scripts/SysprepInstance.ps1 
-NoShutdown"
            ]
        }

    ]
}

Then in *USERDATA2.0.txt* I have:
<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


#Create Folder for Package Source Files (AMI Install Version)
Write-Host "Doing Temp File Folder Creation"
New-Item -Path "c:\" -name "temp" -itemType "directory" -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"
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 2048
cmd.exe /c net stop winrm
cmd.exe /c sc config winrm start= auto
cmd.exe /c net start winrm


</powershell>

Try that setup.



On Wednesday, 6 November 2019 00:06:22 UTC, Mosby Simmons wrote:
>
> I'm new to Packer and trying to get a base image up for Win10.
>
> Is there a good resource somewhere on getting WinRM to work in Packer?
>
> I'm running on a Win10 system with virtualbox and I just can't seem to get 
> WinRM to work.  It just sits there waiting to connect.
>
> I have lines:
>
>   "winrm_insecure": true,
>   "winrm_use_ntlm": true,
>   "winrm_use_ssl": true,
>   "communicator": "winrm",
>       "winrm_username": "vagrant",
>       "winrm_password": "vagrant",
>
> and tried various flavors but no luck.
>
> Also do people usually set winrm information in the autounattend file or 
> as a separate powershell script?  And does it matter?
>
> A little guidance would be very helpful.
>
> TIA.
>

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to packer-tool+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/80ee81c7-9482-4ca3-bd8f-65acc0b17484%40googlegroups.com.

Reply via email to