Project

General

Profile

VMware ESXi » History » Revision 22

Revision 21 (Corey Osman, 12/28/2011 06:19 PM) → Revision 22/23 (Michael Welle, 03/24/2016 04:20 AM)

h1. How to Provision a VMware ESXi server using foreman 

 

 Although Puppet will not run under ESX server we can still use Foreman to kickstart the server using PXE. 

 

 h2. Summary of what you need to do: 

 

 # Copy iso contents of ESXi to your media directory 
 
 # Copy the esx boot files to your tftp directory 
 
 # Create a ESX Installation Medium in Foreman 
 
 # Create a ESX operating system in Foreman 
 
 # Create a ESX partition table (optional) template 
 
 # Create a ESX kickstart template in foreman 
 
 # Create a ESX pxe or gpxe template for ESX in Foreman 


 


 h3. Copy ISO contents of ESXi to your media directory (example only) 

 

 <pre> 
 
 mkdir /mnt/iso1 
 
 mkdir -p /var/www/html/repos/vmware/esxi4.1/   
   
 mount -o loop esxi-iso-file.iso /mnt/iso1    (example for RHEL based distros) 
 
 rsync -avz /mnt/iso1/ /var/www/html/repos/vmware/esxi4.1/ 
 
 </pre> 

 

 h3. Copy the esx boot files to your tftp directory    (must have all of these) 

 

 <pre> 
 
 cp /var/www/html/repos/vmware/esxi4.1/mboot.c32 /var/lib/tftpboot/boot/vmware/ 
 
 cp /var/www/html/repos/vmware/esxi4.1/vmkboot.gz /var/lib/tftpboot/boot/vmware/ 
 
 cp /var/www/html/repos/vmware/esxi4.1/vmkernel.gz /var/lib/tftpboot/boot/vmware/ 
 
 cp /var/www/html/repos/vmware/esxi4.1/sys.vgz /var/lib/tftpboot/boot/vmware/ 
 
 cp /var/www/html/repos/vmware/esxi4.1/cim.vgz /var/lib/tftpboot/boot/vmware/ 
 
 cp /var/www/html/repos/vmware/esxi4.1/ienviron.vgz /var/lib/tftpboot/boot/vmware/ 
 
 cp /var/www/html/repos/vmware/esxi4.1/install.vgz /var/lib/tftpboot/boot/vmware/ 
 
 </pre> 

 

 h3. Create the installation medium based on where you put your esx4.1 iso contents 

 

 # Create new medium 
 
 # vmware 
 
 # path: http://192.168.1.88/repos/vmware/esxi$version/    (example only) 
 
 # OS: ESXi4.1    (can define later after making operating system) 

 

 h3. Create a ESX operating system in foreman (Example only) 

 

 # More-->Operating Systems-->New 
 
 # Name: ESXi 
 
 # Major: 4 
 
 # Minor 1 
 
 # OS Family: Redhat (there is no vmware yet) 
 
 # Arch: x86_64 
 
 # Choose any partition tables if you defined any (can do later) 
 
 # Choose the vmware installation media (can do later)  

  

 h3. Create a Partition table in Foreman (optional) 

 

 # Name: esxi4.1 (name whatever you need to) 
 
 # Assign the template to the ESXi operating system that you defined earlier 
 
 # Layout:    (Something like the following) 
 
 <pre> 
 
 part '/boot'    --fstype=ext3 --size=1100    --ondisk=mpx.vmhba0:C0:T0:L0 
 
 part 'none'    --fstype=vmkcore --size=110    --ondisk=mpx.vmhba0:C0:T0:L0 
 
 part 'datastore1'    --fstype=vmfs3 --size=9004 --grow    --ondisk=mpx.vmhba0:C0:T0:L0 
 
 virtualdisk 'esxconsole' --size=8004 --onvmfs='datastore1' 

 

 part 'swap'    --fstype=swap --size=1000 --onvirtualdisk='esxconsole' 
 
 part '/var/log'    --fstype=ext3 --size=2000 --onvirtualdisk='esxconsole' 
 
 part '/'    --fstype=ext3 --size=5000 --grow --onvirtualdisk='esxconsole' 
 
 </pre> 

 

 h3. Create a ESX kickstart template in foreman 

 

 # More-->provisioning Templates-->new 
 
 # Type: provision 
 
 # Name: esxi 
 
 # Use something like the following for the template: 
 
 <pre> 
 
 vmaccepteula 

 

 install url <%= <%25= @mediapath %> 
 %25> 
 # Set the root password for the DCUI and Tech Support Mode 
 
 rootpw --iscrypted <%= <%25= root_pass %> 

 %25> 

 # required for kickstart 
 
 autopart --firstdisk --overwritevmfs 

 

 # Set the network to DHCP on the first network adapater 
 
 network --bootproto=dhcp --device=vmnic0 

 

 # required for kickstart (foreman doesn't do static IPs yet so will need a way to get around this) 
 
 # if this option is missing the installer will use dhcp 
 
 #network --addvmportgroup=true --device=vmnic0 --vlanid=127 --bootproto=static --ip=10.0.x.3 --netmask=255.255.255.0  
  
 #--gateway=10.0.x.x --nameserver=10.0.x.1,10.0.x.2 --hostname <%= <%25= @host %> 


 <% %25> 


 <%25 if @dynamic -%> 
 %include -%25> 
 %25include /tmp/diskpart.cfg 
 <% 
 <%25 else -%> 
 <%= -%25> 
 <%25= @host.diskLayout %> 
 <% %25> 
 <%25 end -%> 

 -%25> 

 # A sample post-install script 
 %post 
 %25post --unsupported --ignorefailure=true 

 

 # Inform the build system that we are done. 
 
 echo "Informing Foreman that we are built" 
 
 wget -q -O /dev/null --no-check-certificate <%= <%25= foreman_url %> 

 %25> 

 # Configure additional commands at first boot. 
 %firstboot 
 %25firstboot --unsupported --interpreter=busybox 
 
 # Setup VMotion portgroup on vSwitch0 
 
 esxcfg-vswitch -A VMotion vSwitch0 
 
 # Setup VMotion IP address 
 
 esxcfg-vmknic -a VMotion -i [VMKIPADDR] -n 255.255.255.0 
 
 # Wait for previous command to finish before enabling VMotion 
 
 sleep 10 
 
 # Enable VMotion (ESX uses vmware-vim-cmd and ESXi is vim-cmd) 
 
 vim-cmd hostsvc/vmotion/vnic_set vmk1 
 
 vim-cmd hostsvc/net/refresh 
 
 </pre> 

 

 h3. Create a ESX pxe or gpxe template for ESX in foreman 

 

 # More-->provisioning Templates-->new 
 
 # Type: pxelinux or gpxe (untested with gpxe) 
 
 # Name: esxi-pxe 
 
 # Assign the template to the ESXi operating system that you defined earlier 
 
 Do not change anything other than the name and location (boot/vmware) of the template. 
 
 All the files are required and must be in this exact order and with "---" separating each file 
 
 The files referenced below should be referenced from the root of your tftpboot folder    /var/lib/tftpboot/boot/vmware/ 

 

 <pre> 
 
 default ESXi4u1HP-x86_64 
 
 LABEL ESXi4u1HP-x86_64 
         
         kernel /boot/vmware/mboot.c32 
         
         MENU LABEL ESXi4u1HP-x86_64         
                 
         append boot/vmware/vmkboot.gz ks=<%= foreman_url("provision")%> ks=<%25= foreman_url("provision")%25> --- boot/vmware/vmkernel.gz --- boot/vmware/sys.vgz --- boot/vmware/cim.vgz --- boot/vmware/ienviron.vgz --- boot/vmware/install.vgz 
 
 </pre> 

 

 h3. Additional Steps 

 

 # Assign the partition table to the ESXi operating system that you defined earlier 
 
 # Assign the two templates (kickstart, esx-pxe ) to the operating system you defined earlier (more-->operating system-->esx-->templates 

 

 * Note:    Currently you will need to staticly assign the network properties in the kickstart each time until foreman can handle these dynamic attributes 
 
 * Note:    This kickstart will overwrite the vmfs volume so please be careful.   
   
 * Note:    If you remove the the network part the installer will use dhcp and you will need to define your settings after the install. 

 

 Please see the following websites on how to further automate esx settings so your host is ready to go after install 

 

 * "Automating ESXi 4.1 Kickstart Tips & Tricks":http://www.virtuallyghetto.com/2010/09/automating-esxi-41-kickstart-tips.html 
 
 * "PXE and kickstart on ESX 4.x":http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1012248 
 
 * "Vmware Kickstart Options -- Page 35":http://www.vmware.com/pdf/vsphere4/r41/vsp_41_esxi_i_vc_setup_guide.pdf 
 * "ESXi 5.x/6.x deployment with Foreman":http://www.c0t0d0s0.de/esxwithforeman/esxwithforeman.html