Autounattend.xml not running

461 views
Skip to first unread message

martink...@gmail.com

unread,
Nov 6, 2018, 9:11:39 AM11/6/18
to Packer
Hi,

I am fairly new to Packer but i am trying to build a base image for Windows Server 2016 in VirtualBox using Packer and eventually Puppet.

I can get VirtualBox to create the VM etc but it doesn't seem to pick up the autounattend.xml file and run it through.

Server 2016 JSON:
{
   "variables": {
       "zone": "on-prem",
       "customer": "customer",
       "project": "onprem",
       "envname": "prod",
       "role": "web_server",
       "octopus_role": "WebServer",
       "guest_additions_mode": "attach",
       "headless": "false",
       "iso_checksum": "70721288bbcdfe3239d8f8c0fae55f1f",
       "iso_url": "C:\\Users\\profile\\WebServer-Core\\resources\\Windows_Server_2016_eval.ISO",
       "resources": "resources",
       "template_dir": "packer"
   },
   "builders": [
       {
           "type": "virtualbox-iso",
           "vboxmanage": [
               [ "modifyvm", "{{.Name}}", "--memory", "2048" ],
               [ "modifyvm", "{{.Name}}", "--cpus", "2" ]
           ],
           "disk_size": "40000",
           "guest_additions_mode": "{{ user `guest_additions_mode` }}",
           "guest_os_type": "Windows2016_64",
           "headless": "{{ user `headless` }}",
           "iso_url": "{{ user `iso_url` }}",
           "iso_checksum": "{{ user `iso_checksum` }}",
           "iso_checksum_type": "md5",
           "communicator": "winrm",
           "winrm_username": "packer",
           "winrm_password": "packer",
           "winrm_insecure": true,
           "winrm_use_ssl": true,
           "winrm_timeout": "12h",
           "floppy_files": [
               "C:\\Users\\profile\\WebServer-Core\\packer\\include\\autounattend.xml",
               "C:\\Users\\profile\\WebServer-Core\\packer\\include\\winrm.ps1"
           ],
           "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\""
           }
   ]

Autounattend.xml:
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
   <settings pass="windowsPE">
   <!-- look for drivers on floppy -->
   <component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <DriverPaths>
           <PathAndCredentials wcm:keyValue="1" wcm:action="add">
               <Path>A:\</Path>
           </PathAndCredentials>
       </DriverPaths>
   </component>

        <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
           <SetupUILanguage>
               <UILanguage>en-GB</UILanguage>
           </SetupUILanguage>
           <InputLocale>en-GB</InputLocale>
           <SystemLocale>en-GB</SystemLocale>
           <UILanguage>en-GB</UILanguage>
           <UILanguageFallback>en-GB</UILanguageFallback>
           <UserLocale>en-GB</UserLocale>
       </component>
       <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
           <DiskConfiguration>
               <Disk wcm:action="add">
                   <CreatePartitions>
                       <CreatePartition wcm:action="add">
                           <Type>Primary</Type>
                           <Order>1</Order>
                           <Size>50</Size>
                       </CreatePartition>
                       <CreatePartition wcm:action="add">
                           <Order>2</Order>
                           <Type>Primary</Type>
                           <Extend>true</Extend>
                       </CreatePartition>
                   </CreatePartitions>
                   <ModifyPartitions>
                       <ModifyPartition wcm:action="add">
                           <Active>true</Active>
                           <Format>NTFS</Format>
                           <Label>boot</Label>
                           <Order>1</Order>
                           <PartitionID>1</PartitionID>
                       </ModifyPartition>
                       <ModifyPartition wcm:action="add">
                           <Format>NTFS</Format>
                           <Label>Windows 2016</Label>
                           <Letter>C</Letter>
                           <Order>2</Order>
                           <PartitionID>2</PartitionID>
                       </ModifyPartition>
                   </ModifyPartitions>
                   <DiskID>0</DiskID>
                   <WillWipeDisk>true</WillWipeDisk>
               </Disk>
           </DiskConfiguration>
           <ImageInstall>
               <OSImage>
                   <InstallFrom>
                       <MetaData wcm:action="add">
                           <Key>/IMAGE/NAME </Key>
                           <Value>Windows Server 2016 SERVERDATACENTER</Value>
                       </MetaData>
                   </InstallFrom>
                   <InstallTo>
                       <DiskID>0</DiskID>
                       <PartitionID>2</PartitionID>
                   </InstallTo>
               </OSImage>
           </ImageInstall>
           <UserData>
               <ProductKey>
                   <WillShowUI>OnError</WillShowUI>
               </ProductKey>
               <AcceptEula>true</AcceptEula>
               <FullName>ITAdm</FullName>
               <Organization>Customer</Organization>
           </UserData>
       </component>
   </settings>  
 <settings pass="generalize">
   <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SkipRearm>1</SkipRearm>
   </component>
   <component name="Microsoft-Windows-PnpSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <PersistAllDeviceInstalls>false</PersistAllDeviceInstalls>
     <DoNotCleanUpNonPresentDevices>false</DoNotCleanUpNonPresentDevices>
   </component>
 </settings>
 <settings pass="oobeSystem">
   <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <InputLocale>en-GB</InputLocale>
       <SystemLocale>en-GB</SystemLocale>
       <UILanguage>en-GB</UILanguage>
       <UserLocale>en-GB</UserLocale>
   </component>
   <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <OOBE>
               <HideEULAPage>true</HideEULAPage>
               <HideLocalAccountScreen>true</HideLocalAccountScreen>
               <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
               <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
               <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
               <NetworkLocation>Home</NetworkLocation>
               <ProtectYourPC>1</ProtectYourPC>
           </OOBE>
     <TimeZone>Greenwich Standard Time</TimeZone>
     <UserAccounts>
       <AdministratorPassword>
         <Value>packer</Value>
         <PlainText>true</PlainText>
       </AdministratorPassword>
       <LocalAccounts>
         <LocalAccount wcm:action="add">
           <Password>
             <Value>packer</Value>
             <PlainText>true</PlainText>
           </Password>
           <Group>administrators</Group>
           <DisplayName>packer</DisplayName>
           <Name>packer</Name>
           <Description>packer</Description>
         </LocalAccount>
       </LocalAccounts>
     </UserAccounts>
           <AutoLogon>
               <Password>
                   <Value>packer</Value>
                   <PlainText>true</PlainText>
               </Password>
               <Enabled>true</Enabled>
               <Username>packer</Username>
           </AutoLogon>
     <FirstLogonCommands>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine>
           <Description>Set Execution Policy 64 Bit</Description>
           <Order>1</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>C:\Windows\SysWOW64\cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine>
           <Description>Set Execution Policy 32 Bit</Description>
           <Order>2</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm quickconfig -q</CommandLine>
           <Description>winrm quickconfig -q</Description>
           <Order>3</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm quickconfig -transport:http</CommandLine>
           <Description>winrm quickconfig -transport:http</Description>
           <Order>4</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm set winrm/config @{MaxTimeoutms="1800000"}</CommandLine>
           <Description>Win RM MaxTimoutms</Description>
           <Order>5</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm set winrm/config/winrs @{MaxMemoryPerShellMB="800"}</CommandLine>
           <Description>Win RM MaxMemoryPerShellMB</Description>
           <Order>6</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm set winrm/config/service @{AllowUnencrypted="true"}</CommandLine>
           <Description>Win RM AllowUnencrypted</Description>
           <Order>7</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm set winrm/config/service/auth @{Basic="true"}</CommandLine>
           <Description>Win RM auth Basic</Description>
           <Order>8</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm set winrm/config/client/auth @{Basic="true"}</CommandLine>
           <Description>Win RM client auth Basic</Description>
           <Order>9</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port="5985"} </CommandLine>
           <Description>Win RM listener Address/Port</Description>
           <Order>10</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes </CommandLine>
           <Description>Win RM adv firewall enable</Description>
           <Order>11</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c netsh firewall add portopening TCP 5985 "Port 5985" </CommandLine>
           <Description>Win RM port open</Description>
           <Order>12</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c net stop winrm </CommandLine>
           <Description>Stop Win RM Service </Description>
           <Order>13</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c sc config winrm start= auto</CommandLine>
           <Description>Win RM Autostart</Description>
           <Order>14</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
       <SynchronousCommand wcm:action="add">
           <CommandLine>cmd.exe /c net start winrm</CommandLine>
           <Description>Start Win RM Service</Description>
           <Order>15</Order>
           <RequiresUserInput>true</RequiresUserInput>
       </SynchronousCommand>
     </FirstLogonCommands>
   </component>
 </settings>
   <settings pass="specialize">
       <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
           <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon>
       </component>
       <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
           <IEHardenAdmin>false</IEHardenAdmin>
           <IEHardenUser>false</IEHardenUser>
       </component>
       <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
           <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon>
       </component>
   </settings>
</unattend>


But all i see after running the packer build is:

vbox-server2016.PNG



















Which seems like its booted the Windows ISO but isn't picking up the autounattend.xml.

Does anyone have any ideas please?

TIA

martink...@gmail.com

unread,
Nov 6, 2018, 11:07:22 AM11/6/18
to Packer
UPDATE: managed to get it working, apparently how i am using the localisations of en-GB, doesn't work. I changed to en-US and it works, builds the machine and runs the WinRM scripts as needed.

Anyone know how i can use en-GB?

Also i am now getting stuck at 'virtualbox-iso: Waiting for WinRM to become available...', i have checked the FW rules and the service is started etc but it just hangs at that point, any ideas from anyone?

TIA

JP Toto

unread,
Nov 6, 2018, 11:12:05 AM11/6/18
to packe...@googlegroups.com
Martin,

You may need to specify the WinRM port or turn off ssl. depending on the defaults that Windows Server 2016 is doing. You can also check out the boxcutter Windows 2016 Packer file which is a good reference https://github.com/boxcutter/windows/blob/master/eval-win2016-standard.json In fact that whole repo is great.



--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/aff922e0-5ca3-4524-a3d9-d9f3d137f0ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
JP Toto   |   james....@gmail.com   |   http://jptoto.jp   |   @jptoto

JP Toto

unread,
Nov 6, 2018, 11:12:45 AM11/6/18
to packe...@googlegroups.com
This is also a good blog post about some best practices https://hodgkins.io/best-practices-with-packer-and-windows

martink...@gmail.com

unread,
Nov 8, 2018, 9:14:14 AM11/8/18
to Packer
Thank you - it seems that turning off SSL did the trick :) 

Pandit Mali

unread,
Feb 19, 2019, 4:32:08 PM2/19/19
to Packer
Hi Sir,

I am looking assistance from you for build Windows server 2016 using packer tool.

I have ps1 script files with me but upload and run the same Azure cloud, Please help me to how I need to use the packer tool build the custom OS.


Regards,
Pandit
Reply all
Reply to author
Forward
0 new messages