Automate Windows Server 2019 Core Installation and Deployment

As detailed in the previous post yesterday, Windows Server 2019 Core edition is gaining momentum among customers as the go to Windows edition for installation in their environments. Due to great new tools and extensions such as Windows Admin Center and Feature on Demand (FoD), the Core edition has much better support for admin interaction than previous Core releases. You will no doubt want to start automating your deployment of Windows Server 2019 Core edition. This can easily be done with a few tools such as Hashicorp packer and customization specifications. In this post, we will take a look at a few key concepts in automate Windows Server 2019 Core installation and deployment in a VMware vSphere environment for quick provisioning of Windows Server 2019 servers.

Getting Started with Hashicorp Packer

I have written a few posts already regarding Hashicorp Packer. Below are the links to those posts for your reference.
  • Automated Windows 10 Installation with AutoUnattend and Packer
  • Create Unattend Answer File for Windows Server 2019 Automated Packer Installation
  • Getting Started with Packer and VMware vSphere
Packer is a great tool to use for an automated solution that is easy automate the creation of any type of machine image. It works with configuration management solutions and helps to facilitate automation with scripting to install and configure software within Packer provisioned images. The great thing about Packer provisioned images is that it allows you to have an automated solution for keeping ready to provision images that are up-to-date with the latest software and other configurations that are introduced in your configuration pipeline.
It works out of the box and comes with support to build images for Amazon, EC2, CloudStack, DigitalOcean, Docker, Google Compute Engine, Microsoft Azure, QEMU, VirtualBox, VMware, and more platforms are in the works with Packer.
The entire Hashicorp ecosystem is becoming (may already be) the gold standard for many enterprise environments and their automation initiatives. From an image building perspective, Packer is a great tool for use with provisioning and getting started with automation initiatives.
Packer itself is a simple executable written in GO that is self contained and ready to use. There are only a few components that you need to have in place for using Packer to build images in a VMware vSphere environment. For my vSphere environment in the lab I have the following:
Placing-all-the-Packer-resources-in-a-common-directory Automate Windows Server 2019 Core Installation and Deployment
Placing all the Packer resources in a common directory

Setting Up Files and Resources

I have my packer resource JSON files setup in a Git repository. This is not required but allows a great way to keep up with file versioning, etc. You will need four additional files for successfully automating a basic Windows Server 2019 Core VM image.
  • Windows Server 2019 ISO
  • VARs JSON file
  • Builder manifest file
  • Unattended Answer File (XML)
Make sure under the floppy files section to change the path to your Unattended installation file to line up with your directory structure.

Packer Builder Manifest File

  1. {
  2. "variables": {
  3. "vsphere_server": "",
  4. "vsphere_user": "",
  5. "vsphere_password": "",
  6. "vsphere_template_name": "",
  7. "vsphere_folder": "",
  8. "vsphere_dc_name": "",
  9. "vsphere_compute_cluster": "",
  10. "vsphere_host": "",
  11. "vsphere_portgroup_name": "",
  12. "vsphere_datastore": "",
  13. "winadmin_password": "",
  14. "cpu_num": "",
  15. "mem_size": "",
  16. "disk_size": "",
  17. "os_iso_path": "",
  18. "vmtools_iso_path":""
  19. },
  20. "sensitive-variables": ["vsphere_password", "winadmin_password"],
  21. "builders": [
  22. {
  23. "type": "vsphere-iso",
  24. "vcenter_server": "{{user `vsphere_server`}}",
  25. "username": "{{user `vsphere_user`}}",
  26. "password": "{{user `vsphere_password`}}",
  27. "insecure_connection": "true",
  28. "vm_name": "{{user `vsphere_template_name`}}",
  29. "folder" : "{{user `vsphere_folder`}}",
  30. "datacenter": "{{user `vsphere_dc_name`}}",
  31. "cluster": "{{user `vsphere_compute_cluster`}}",
  32. "host": "{{user `vsphere_host`}}",
  33. "network": "{{user `vsphere_portgroup_name`}}",
  34. "datastore": "{{user `vsphere_datastore`}}",
  35. "convert_to_template": "true",
  36. "guest_os_type": "windows9Server64Guest",
  37. "communicator": "winrm",
  38. "winrm_username": "Administrator",
  39. "winrm_password": "{{user `winadmin_password`}}",
  40. "CPUs": "{{user `cpu_num`}}",
  41. "RAM": "{{user `mem_size`}}",
  42. "RAM_reserve_all": true,
  43. "firmware": "bios",
  44. "disk_controller_type": "lsilogic-sas",
  45. "disk_size": "{{user `disk_size`}}",
  46. "disk_thin_provisioned": true,
  47. "network_card": "vmxnet3",
  48. "iso_paths": [
  49. "{{user `os_iso_path`}}",
  50. "{{user `vmtools_iso_path`}}"
  51. ],
  52. "floppy_files": [
  53. "setup/win19core/autounattend.xml",
  54. "setup/setup.ps1",
  55. "setup/vmtools.cmd"
  56. ]
  57. }
  58. ],
  59. "provisioners": [
  60. {
  61. "type": "windows-shell",
  62. "inline": ["dir c:\\"]
  63. }
  64. ]
  65. }

Packer Variables File

In your variables file, this is where you customize for your environment. This will include specific information regarding your vSphere infrastructure including vCenter Server address, logins, datastore, Datacenter, cluster, and other information. Notice also, you will need to copy your VMware Tools Windows ISO to your datastore as well where the ISO can be accessed with the Packer build process to install VMware Tools in your installation of Windows Server 2019 Core.
Checklist:
  • Replace vSphere specific information in the variables file
  • Create the Templates folder being referenced
  • Upload the Windows Server 2019 installation media to the folder you reference
  • Upload the VMware Tools Windows ISO
  • Change name of installation media in os_iso_path variable
Also, replace the name of the Windows ISO with the file name of the current download you use for the installation media.
  1. {
  2. "vsphere_server": "<your vCenter FQDN>",
  3. "vsphere_user": "administrator@vsphere.local",
  4. "vsphere_password": "<vCenter password>",
  5. "vsphere_template_name": "Win2019Coreclone",
  6. "vsphere_folder": "Templates",
  7. "vsphere_dc_name": "<Your DC Name>",
  8. "vsphere_compute_cluster": "<Your Cluster name>"
  9. "vsphere_portgroup_name": "<Your vSwitch portgroup label>",
  10. "vsphere_datastore": "<Your datastore>",
  11. "winadmin_password": "<your Windows password>",
  12. "cpu_num": "4",
  13. "mem_size": "4096",
  14. "disk_size": "102400",
  15. "os_iso_path": "[<your datastore>] ISO/en_windows_server_2019_updated_march_2019_x64_dvd_2ae967ab.iso",
  16. "vmtools_iso_path":"[Your Datastore] ISO/windows.iso"
  17. }

Windows Server 2019 Core Edition Unattended Installation Answer File

To install the Windows Server 2019 Core edition, you need to make sure you have the OSImage value set to:
  • Windows Server 2019 SERVERSTANDARDCORE
Make sure you customize the answer file for your environment, including the ProductKeyAutologonUserAccounts, and other configuration.
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <unattend xmlns="urn:schemas-microsoft-com:unattend">
  3. <settings pass="windowsPE">
  4. <component name="Microsoft-Windows-International-Core-WinPE" 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">
  5. <SetupUILanguage>
  6. <UILanguage>en-US</UILanguage>
  7. </SetupUILanguage>
  8. <InputLocale>en-US</InputLocale>
  9. <SystemLocale>en-US</SystemLocale>
  10. <UILanguage>en-US</UILanguage>
  11. <UserLocale>en-US</UserLocale>
  12. </component>
  13. <component name="Microsoft-Windows-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">
  14. <DiskConfiguration>
  15. <Disk wcm:action="add">
  16. <CreatePartitions>
  17. <CreatePartition wcm:action="add">
  18. <Order>1</Order>
  19. <Size>500</Size>
  20. <Type>Primary</Type>
  21. </CreatePartition>
  22. <CreatePartition wcm:action="add">
  23. <Order>2</Order>
  24. <Extend>true</Extend>
  25. <Type>Primary</Type>
  26. </CreatePartition>
  27. </CreatePartitions>
  28. <ModifyPartitions>
  29. <ModifyPartition wcm:action="add">
  30. <Order>1</Order>
  31. <PartitionID>1</PartitionID>
  32. <Format>NTFS</Format>
  33. <Label>Boot</Label>
  34. <Active>true</Active>
  35. </ModifyPartition>
  36. <ModifyPartition wcm:action="add">
  37. <Order>2</Order>
  38. <PartitionID>2</PartitionID>
  39. <Format>NTFS</Format>
  40. <Label>System</Label>
  41. </ModifyPartition>
  42. </ModifyPartitions>
  43. <DiskID>0</DiskID>
  44. <WillWipeDisk>true</WillWipeDisk>
  45. </Disk>
  46. </DiskConfiguration>
  47. <ImageInstall>
  48. <OSImage>
  49. <InstallFrom>
  50. <MetaData wcm:action="add">
  51. <Key>/IMAGE/NAME</Key>
  52. <Value>Windows Server 2019 SERVERSTANDARDCORE</Value>
  53. </MetaData>
  54. </InstallFrom>
  55. <InstallTo>
  56. <DiskID>0</DiskID>
  57. <PartitionID>2</PartitionID>
  58. </InstallTo>
  59. <WillShowUI>OnError</WillShowUI>
  60. <InstallToAvailablePartition>false</InstallToAvailablePartition>
  61. </OSImage>
  62. </ImageInstall>
  63. <UserData>
  64. <AcceptEula>true</AcceptEula>
  65. <ProductKey>
  66. <Key>11111-22222-33333-44444-55555</Key>
  67. <WillShowUI>Never</WillShowUI>
  68. </ProductKey>
  69. </UserData>
  70. </component>
  71. </settings>
  72. <settings pass="specialize">
  73. <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">
  74. <TimeZone>Central Standard Time</TimeZone>
  75. </component>
  76. <component name="Microsoft-Windows-Deployment" 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">
  77. <RunSynchronous>
  78. <RunSynchronousCommand wcm:action="add">
  79. <Path>a:\vmtools.cmd</Path>
  80. <Order>1</Order>
  81. <WillReboot>Always</WillReboot>
  82. </RunSynchronousCommand>
  83. </RunSynchronous>
  84. </component>
  85. <component name="Microsoft-Windows-TerminalServices-LocalSessionManager" 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">
  86. <fDenyTSConnections>false</fDenyTSConnections>
  87. </component>
  88. <component name="Networking-MPSSVC-Svc" 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">
  89. <FirewallGroups>
  90. <FirewallGroup wcm:action="add" wcm:keyValue="RemoteDesktop">
  91. <Active>true</Active>
  92. <Group>Remote Desktop</Group>
  93. <Profile>all</Profile>
  94. </FirewallGroup>
  95. </FirewallGroups>
  96. </component>
  97. <component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" 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">
  98. <SecurityLayer>2</SecurityLayer>
  99. <UserAuthentication>1</UserAuthentication>
  100. </component>
  101. <component name="Microsoft-Windows-ServerManager-SvrMgrNc" 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">
  102. <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon>
  103. </component>
  104. </settings>
  105. <settings pass="oobeSystem">
  106. <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">
  107. <AutoLogon>
  108. <Password>
  109. <Value>Yourpassword</Value>
  110. <PlainText>true</PlainText>
  111. </Password>
  112. <LogonCount>3</LogonCount>
  113. <Username>Administrator</Username>
  114. <Enabled>true</Enabled>
  115. </AutoLogon>
  116. <FirstLogonCommands>
  117. <SynchronousCommand wcm:action="add">
  118. <Order>1</Order>
  119. <!-- Enable WinRM service -->
  120. <CommandLine>powershell -ExecutionPolicy Bypass -File a:\setup.ps1</CommandLine>
  121. <RequiresUserInput>true</RequiresUserInput>
  122. </SynchronousCommand>
  123. <SynchronousCommand wcm:action="add">
  124. <CommandLine>DoNotOpenServerManagerAtLogon = true</CommandLine>
  125. <Order>10</Order>
  126. </SynchronousCommand>
  127. </FirstLogonCommands>
  128. <UserAccounts>
  129. <AdministratorPassword>
  130. <Value>Yourpassword</Value>
  131. <PlainText>true</PlainText>
  132. </AdministratorPassword>
  133. </UserAccounts>
  134. </component>
  135. </settings>
  136. <cpi:offlineImage cpi:source="wim:c:/users/administrator/desktop/win2016/install.wim#Windows Server 2019 SERVERSTANDARDCORE" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
  137. </unattend>

Automate Windows Server 2019 Core Installation and Deployment

Let’s put it altogether and see what the build of Windows Server 2019 Core looks like using Packer. Here, we simply call the files that we have built above:
  • packer build -var-file <your var file> <your manifest file>
Automate-Windows-Server-2019-Core-Installation-and-Deployment Automate Windows Server 2019 Core Installation and Deployment
The great thing about the Packer builds is you can have custom scripts that run during installation that install or configure various aspects of your Windows Server 2019 core installation. For instance, below, I have a script to install Windows Updates inside of the Windows Server 2019 Core installation.
Get more details on how to perform automated installation of Windows Updates in Windows Server 2019 here:
  • Windows Server 2019 Automating Windows Update with PowerShell and Logs
Packer-is-building-the-Windows-Server-2019-Core-VM-along-with-other-scripts-for-customization Automate Windows Server 2019 Core Installation and Deployment
Packer is building the Windows Server 2019 Core VM along with other scripts for customization
After a short while, you should see your Windows Server 2019 Core installation complete and be converted to a VMware template by Packer.
After you have your template in place, you can now clone from the template and make use of any customization specifications you may have for further customizing of the deployed template.

Wrapping Up

Packer is a great tool to Automate Windows Server 2019 Core Installation and Deployment. It makes the process to build Windows images extremely easy in VMware vSphere and many other provider environments, including the cloud.
The great thing about the Packer utility is you can schedule it to run periodically so that you can always have an up-to-date Windows Server 2019 Core image available for deployment when you need it.

Post a Comment

0 Comments