The Foreman PXE provisioning with LibvirtPosted: October 16, 2013
More than just a Puppet management interface The Foreman can handle the whole lifecycle of servers, from their creations and provisioning (pxe + kickstart/preseed) to their management (puppet). Today’s blog post will highlight how to use the provisioning feature of The Foreman using Libvirt DHCP server (dnsmasq) for local testing purpose.
- An instance of a VM running foreman on libvirt, for this post version 1.3.0 of The Foreman is used, and CentOS 6.4 will be deployed.
Create the Operating System (The Foreman)
The Operating System
In the first time, simply fill the four first field and click submit. We will get back to it at a later point.
Path : More -> Provisioning -> Operating Systems -> New Operating System
Add an architecture one will be supporting for a set of OSes
Path : More -> Provisioning -> Architectures -> New Architecture
The Installation Media
For our case, the CentOS installation media already exist, one still have to click on CentOS and specify RedHat as Operating System family.
If you have a local mirror of CentOS repositories you could simply make the path points to it, installation will be much faster.
Path : More -> Provisioning -> Installation Media
The Partion Table
A RedHat default partition tables is already present, for the purpose of the demo we will be using it but you might want to create your own one. Do not forget to specify the Operating System Family.
Path : More -> Provisioning -> Partition Tables
The provisiong template section is where one defines its kickstart/preseed, PXE, gPXE, etc… scripts.
One can define snippets that can be embedded within scripts.
For the demo purpose we will be using two pre-existing scripts
- Kickstart Default PXELinux (PXELinux)
- Kickstart Default (provision)
Once one clicks on the Template, one needs to go the the Association tab on the presented page to associate it with the proper OS. Here it needs to be done twice for the Kickstart Default PXELinux and for the Kickstart Default scripts.
Path : More -> Provisioning -> The Provisioning Templates
The Operating System
And back to the Operating System to bind it all together.
Path : More -> Provisioning -> Operating Systems -> CentOS 6.4
First you should be presented with the following page, pick the right options (Architecture, Partition Tables, Installation Media) for your OS
Now go to template and associate the template accordingly
You can now save the OS.
Create the domain (The Foreman)
Here nothing fancy, simply fill up what is prompted. In the current scenario we don’t use The Foreman as a DNS.
Path : More -> Provisioning -> Domains -> New Domain
Create the Subnet (The Foreman)
Here the Network Address is the one from your libvirt’s dnsmasq configuration. Normally you can guess if from a simple ifconfig eth0, else on the host run virsh net-dumpxml default, assuming you run the default network. Same thing applies for the Network Mask.
Select the appropriate domain (cf. Create The Domain) and then the most important make sure the smart proxy name is selected in the TFTP Proxy box.
Path : More -> Provisioning -> Subnets -> New Subnet
Create the VM with PXE boot (Libvirt)
Create the New VM with a PXE boot
For now you can stop the VM since the DHCP server is not configured. Please note the MAC address of the Virtual Machine, it will be needed on the later section
Configure dnsmasq for IP attribution and PXE boot (Libvirt)
Note your foreman VM and your node1 VM MAC addresses.
Stop your foreman VM now.
1. Destroy the network
virsh net-destroy default
2. Edit the current network to assign static ip
virsh net-edit default
<ip address='192.168.100.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.100.128' end='192.168.100.254' /> </dhcp> </ip>
<ip address='192.168.100.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.100.128' end='192.168.100.254' /> <host mac='52:54:00:CB:C3:C6' name='foreman' ip='192.168.100.169' /> <host mac='52:54:00:89:2A:7E' name='node1' ip='192.168.100.170' /> <bootp file='pxelinux.0' server='192.168.100.169' /> </dhcp> </ip>
3. Restart the network
virsh net-start default
What is being done here at step 2, is a static assignement of IP addresses by the DHCP server and the configuration of the PXE boot.
Static Assignement of IP address
<host mac='52:54:00:CB:C3:C6' name='foreman' ip='192.168.100.169' />
Here we tell dnsmasq that device with MAC address ’52:54:00:CB:C3:C6′ will always be assigned ip ‘192.168.100.169’
PXE Boot Configuration
<bootp file='pxelinux.0' server='192.168.100.169' />
He we tell devices that wish to do PXE boot, to get the file pxelinux.0 on the tftp server running on 192.168.100.169
You can now start the foreman VM, not node1 yet.
Create the Host (The Foreman)
Here fill up the information as needed, the specifics to PXE provisioning are the Network and Operating System tabs.
- In the Network tab, fill up the MAC address, the configured domain, subnet and the IP Address assigned in DHCP server.
- In the Operating System tab, select the Operating System you want your VM to be. (cf. Configure the Operating System)
Path : Hosts -> New Host
Start the VM (Libvirt)
Simply start the node1 VM, it will be assigned the static IP address and will retrieve the pxelinux.0 from the foreman server as specified in the DHCP server. It might take some time while the installation is processing.
Once the VM automatically rebooted, one needs to go to the foreman > hosts page and will see that the node1 is in a ‘No Changes’ state, meaning build was successful, puppet connected. The VM is now fully managed by The Foreman.
One can configure as many OSes as one wants with fully configurable kickstart/preseed scripts, themselves dynamically parametrizable. As of today, The Foreman is a solid solution to manage the whole lifcycle of servers, from creation to provisioning to management, providing the user with details – filtrable – reports of what is going on. On a personal note I would say that if you are managing puppet servers and you are not using The Foreman, you are doing it wrong. QED.
- The Foreman Manual http://theforeman.org/manuals/1.3/index.html
- Dominic Cleal Youtube’s videos about unattended installation http://www.youtube.com/watch?v=eHjpZr3GB6s