RLabs: Provisioning Windows with Foreman on VMware from template

Ok, so now you have connected Foreman with VMware you want to start creating Windows VMs.

Creating a Windows Server 2016 VM template

You´ll need to create a template VM on VMware first.

Download the Windows .iso image and upload it to a VMware datastore.

Installing Windows Server 2016

Create a VM called WinSrv2016full with 2Gb of RAM, 1vCPU and a minimum of 15Gb of disk. You will need at least 30Gb if you want to update it – highly recommended.
Set an administrator password during installation. Later I´ve set it to adminadmin.

 

Configure the VM

Install VMware Tools, but don´t reboot.
Set timezone to UTC (my personal choice) and add pool.ntp.org as NTP server.
Enable Remote Desktop connection.
Disable windows firewall (don´t to this in production).
Change IE security configuration to Off.
Don´t activate windows yet.
Update the system only if you have configured a 30Gb disk.
Shutdown the VM.

Add another SCSI controller type VMware Paravirtual.
Delete the actual network interface and attach a new one, type VMXNET.
Remove the CD configuration to point to a Client Device and not connected.
Power on the VM.
Configure the DNS servers to 192.168.12.2 and 1.1.1.1.
Shutdown again.

Remove the recently added SCSI controller.
Change the type of the existing controller to VMware Paravirtual.
Boot up the VM and test if everything is OK.

Shutdown the VM and convert it to template.

Create OS and architecture

Go to Hosts->Architecture->Create new architecture.
Name it x64.

Go to Hosts-> Operating system->Create operating system:

Screenshot 2018-10-02 00.15.11.png

 

Import the template as an Image in the compute resource

Go to Infrastructure->Compute resource->DC1_VMware and click on “Create image”.

Enter required information as follow:

Screenshot 2018-10-02 00.55.27.png

NOTE: Don´t forget to check the userdate box.

Creating a Windows Server 2016 Core VM template

Same steps, renaming WinSrv2016full to WinSrv2016core.

Create a compute profile

Go to Infrastructure->Compute profile->Create compute profile.
Name it DC1VMW_Windows and select the DC1_VMware compute resource.
Configure it as follow:

Screenshot 2018-10-02 00.57.56.png

Screenshot 2018-10-02 00.58.41.png

Configure the Windows OS on Foreman

User_data script

We´ll need a user_data template to create VMs based on VMware templates.
What happens is that Foreman will convert it to a customization spec on VMware that will be applied on the first boot of the VM.

Go to Hosts->Provisioning Templates->Create template.
Name it “VMware_windows_userdata”.
Type: User data template.
Association: select windows.
On the template text field, paste this:

<%-
  powershell = '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -NoLogo -NoProfile'
-%>
---
identity:
  Sysprep:
    guiRunOnce:
      commandList:
        - '<%= powershell %> -Command "invoke-webrequest -Uri <%= foreman_url("built") %>"'
        - '<%= powershell %> -Command "invoke-webrequest -Uri http://downloads.puppet.com/windows/puppet-agent-x64-latest.msi -OutFile C:\puppet-agent-x64-latest.msi"'
        - '<%= powershell %> -Command "msiexec /qn /norestart /i C:\puppet-agent-x64-latest.msi PUPPET_MASTER_SERVER=<%= @host.puppetmaster %>"'
    guiUnattended:
      autoLogon: true
      autoLogonCount: 1
      password:
        plainText: true
        value: 'adminadmin'
      timeZone: 090
    identification:
      joinWorkgroup: 'WORKGROUP'
    licenseFilePrintData:
      autoMode: 'perSeat'
    userData:
      computerName: <%= @host.shortname %>
      fullName: 'IT'
      orgName: <%= @host.organization %>
      productId: <%= host_param('windows_serial') %>
nicSettingMap:
  - adapter:
      dnsDomain: <%= @host.domain %>
      dnsServerList:
        - <%= @host.subnet.dns_primary %>
      gateway:
        - <%= @host.subnet.gateway %>
      ip: <%= @host.ip %>
      subnetMask: <%= @host.subnet.mask %>
globalIPSettings:
  dnsServerList:
    - <%= @host.subnet.dns_primary %>
  dnsSuffixList:
    - <%= @host.domain %>
options:
  changeSID: true
  deleteAccounts: false


Customize the Windows operating system

Go to Hosts->Operating systems and click on the Windows OS.
Go to the templates tab and set user data to VMware_windows_userdata, then submit.

Windows Product Key

Create a global paremeter “windows_serial” with your product key.

Create a “Generic Windows” hostgroup

You don´t need it, but it is very recommended so you can set many default values instead of setting them everytime you create a VM.

Go to Configure->Hostgroups->Create hostgroup.
Name it “Generic Windows”.

On the first screen, use the following values:

Screenshot 2018-10-02 01.09.37.png

On the network tab:

Screenshot 2018-09-29 18.57.57.png

On the OS tab:

Screenshot 2018-10-02 01.10.03.png

 

Create a test VM

Ok, so let´s create a VM for testing !

Go to Hosts->Create host

Populate as follow:

 

On the Operating System tab:

 

 

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s