Notice:
This post is older than 5 years – the content might be outdated.
In Foreman Provision: A Comfortable Resource Management Tool for Foreman we learned how to deploy CentOS Linux Hosts with Foreman. Now what if we instead need to deploy Microsoft’s Windows Server? Read on for a detailed walkthrough.
Despite the fact that Foreman was primarily built to deploy free operating systems like GNU/Linux and *BSD you can make use of vSphere VM templates to deploy new Windows systems.
Technical Requirements
In order to start deploying Windows we need to install additional Foreman packages for VMware vSphere Compute Resource support.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# cat /etc/yum.repos.d/foreman*.repo [foreman-plugins] name=Foreman stable plugins repository baseurl=http://yum.theforeman.org/plugins/latest/el7/$basearch enabled=1 gpgcheck=0 [foreman_proxy-plugins] name=Foreman stable plugins repository baseurl=http://yum.theforeman.org/plugins/latest/el7/$basearch enabled=1 gpgcheck=0 [foreman_proxy] name=Foreman stable repository baseurl=http://yum.theforeman.org/releases/latest/el7/$basearch enabled=1 gpgcheck=1 gpgkey=http://yum.theforeman.org/releases/latest/RPM-GPG-KEY-foreman [foreman] name=Foreman stable repository baseurl=http://yum.theforeman.org/releases/latest/el7/$basearch enabled=1 gpgcheck=1 gpgkey=http://yum.theforeman.org/releases/latest/RPM-GPG-KEY-foreman # yum repolist | grep foreman foreman/x86_64 Foreman stable repository 379 foreman-plugins/x86_64 Foreman stable plugins repository 201 foreman_proxy/x86_64 Foreman stable repository 379 foreman_proxy-plugins/x86_64 Foreman stable plugins repository 201 # cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) # yum install foreman-vmware |
Now we see „VMware“ provider support has been installed.
For further steps we need the following setup:
- VMware Version 5.5.0 Build 2414847
- vSphere template containing Windows Server 2008 R2
- A vSphere/ vCenter user that has sufficient access to deploy VMs via vCenter
Preparing Windows Deployment
The first step to prepare Windows deployment is to add a new compute resource of type „VMware“:
Here we make use of Fog, a library that provides management of virtual resources for private and public IaaS/SaaS (a.k.a. Cloud) providers. With the most recent release of Foreman, we get Fog 1.32 which is also listed in the Foreman 1.9 changelog. The VMware customization feature modifies the guest operating system of a newly created virtual machine to prevent having hosts in a network that have the same network configuration, SSID, serial number and so on.
The next step is to add a Windows operating system and a compute resource image in Foreman.
When creating the image you might have noticed the checkbox with the label „User data“. User data is a Foreman provision template that Fog will translate into an XML tree that matches VMware’s customization specification. Create a new provision template with the following content, set the type „user_data“ and associate it with the Foreman Windows operating system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
<%- powershell = '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -NoLogo -NoProfile' -%> --- identity: Sysprep: guiRunOnce: commandList: - '<%= powershell %> -Command "invoke-webrequest -Uri https://raw.githubusercontent.com/bechtoldt/puppet-bootstrap/master/windows.ps1 -Outfile c:\puppet-windows.ps1"' - '<%= powershell %> -Command "& \'.\windows.ps1 -PuppetVersion 3.7.5\'"' - '<%= powershell %> -Command "invoke-webrequest -Uri <%= foreman_url("built") %>"' guiUnattended: autoLogon: true autoLogonCount: 1 password: plainText: true value: 'testpass123' timeZone: 110 identification: joinWorkgroup: 'WORKGROUP' licenseFilePrintData: autoMode: 'perSeat' userData: computerName: <%= @host.shortname %> fullName: 'IT' orgName: 'inovex GmbH' productId: 'D2N9P-3P6X9-2R39C-7RTCD-MDVJX' 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 |
Finally the Windows operating system needs to be associated with the newly created user_data template, too.
With this being done you will be able to create new hosts (VMs) in VMware and specify the VMware template (here: „winabechtoldt-8-TEMPLATE“) as image. The compute/“cloud“ library Fog that is used by Foreman will create a new VMware VM, clone the template disk (our image), boot the VM and initiate all the Windows-specific actions/customizations:
- NIC IP configuration
- workgroup/domain join
- activate a license using the product ID (serial number)
- triggers finish/post-install commands (install Puppet & tell Foreman that the build has completed)
- etc.
In case you need to deploy Windows on bare metal you may want to use one of the widely used image deployment concepts in combination with Foreman. You’d need to let Windows start some scripts like the PowerShell script puppet-windows.ps1 that installs Puppet.
However, deploying Windows on bare metal might be handled in a future blog post. 🙂
Have fun deploying Windows using Foreman!
Credits
Thanks to the people that have contributed the following articles and sources:
- http://www.herbert.org.nz/?p=245
- http://projects.theforeman.org/issues/8601
- https://github.com/theforeman/foreman/pull/2000
We’re hiring!
Looking for a change? We’re hiring DevOps Engineers experienced with NodeJS, Git, Jenkins, Puppet and of course Foreman. Apply now!
Get in touch
Interested in automation and virtualization? Check out the IT Engineering section on our website, call +49 721 619 021-0 or drop us an email.
Hello,
Do you have any blog created for bare-metal servers ?
Thanks,
DJ
hey @disqus_r7a425D4yg:disqus ,
There are no blog posts for windows bare-metal deployment yet, but I think my colleagues regulariy did this in the past. 🙂
Arnold