Project

General

Profile

VMware ESXi » History » Version 15

Corey Osman, 12/27/2011 10:59 PM

1 1 Corey Osman
h1. How to Provision a VMware ESXi server using foreman
2 1 Corey Osman
3 1 Corey Osman
Although puppet will not run under ESX server we can still use foreman to kickstart the server using PXE.
4 1 Corey Osman
5 1 Corey Osman
h2. Summary of what you need to do:
6 1 Corey Osman
# Copy iso contents of ESXi to your media directory
7 1 Corey Osman
# Copy the esx boot files to your tftp directory
8 8 Corey Osman
# Create a ESX Installation Medium in Foreman
9 1 Corey Osman
# Create a ESX operating system in foreman
10 1 Corey Osman
# Create a ESX partition table (optional) template
11 1 Corey Osman
# Create a ESX kickstart template in foreman
12 1 Corey Osman
# Create a ESX pxe or gpxe template for ESX in foreman
13 1 Corey Osman
14 1 Corey Osman
15 4 Corey Osman
h3. Copy iso contents of ESXi to your media directory (example only)
16 1 Corey Osman
<pre>
17 6 Corey Osman
mkdir /mnt/iso1
18 6 Corey Osman
mkdir -p /var/www/html/repos/vmware/esxi4.1/  
19 5 Corey Osman
mount -o loop esxi-iso-file.iso /mnt/iso1  (example for RHEL based distros)
20 4 Corey Osman
rsync -avz /mnt/iso1/ /var/www/html/repos/vmware/esxi4.1/
21 4 Corey Osman
</pre>
22 4 Corey Osman
23 7 Corey Osman
h3. Copy the esx boot files to your tftp directory  (must have all of these)
24 4 Corey Osman
<pre>
25 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/mboot.c32 /var/lib/tftpboot/boot/vmware/
26 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/vmkboot.gz /var/lib/tftpboot/boot/vmware/
27 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/vmkernel.gz /var/lib/tftpboot/boot/vmware/
28 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/sys.vgz /var/lib/tftpboot/boot/vmware/
29 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/cim.vgz /var/lib/tftpboot/boot/vmware/
30 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/ienviron.vgz /var/lib/tftpboot/boot/vmware/
31 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/install.vgz /var/lib/tftpboot/boot/vmware/
32 4 Corey Osman
33 2 Corey Osman
</pre>
34 8 Corey Osman
35 9 Corey Osman
h3. Create the installation medium based on where you put your esx4.1 iso contents
36 9 Corey Osman
# Create new medium
37 9 Corey Osman
# vmware
38 9 Corey Osman
# path: http://192.168.1.88/repos/vmware/esxi$version/  (example only)
39 9 Corey Osman
# OS: ESXi4.1  (can define later after making operating system)
40 9 Corey Osman
41 8 Corey Osman
h3. Create a ESX operating system in foreman (Example only)
42 8 Corey Osman
# More-->Operating Systems-->New
43 8 Corey Osman
# Name: ESXi
44 8 Corey Osman
# Major: 4
45 8 Corey Osman
# Minor 1
46 8 Corey Osman
# OS Family: Redhat (there is no vmware yet)
47 8 Corey Osman
# Arch: x86_64
48 8 Corey Osman
# Choose any partition tables if you defined any (can do later)
49 1 Corey Osman
# Choose the vmware installation media (can do later) 
50 1 Corey Osman
51 10 Corey Osman
 h3. Create a Partition table in Foreman (optional)
52 1 Corey Osman
# Name: esxi4.1 (name whatever you need to)
53 13 Corey Osman
# Assign the template to the ESXi operating system that you defined earlier
54 9 Corey Osman
# Layout:  (Something like the following)
55 9 Corey Osman
<pre>
56 9 Corey Osman
part '/boot'  --fstype=ext3 --size=1100  --ondisk=mpx.vmhba0:C0:T0:L0
57 9 Corey Osman
part 'none'  --fstype=vmkcore --size=110  --ondisk=mpx.vmhba0:C0:T0:L0
58 9 Corey Osman
part 'datastore1'  --fstype=vmfs3 --size=9004 --grow  --ondisk=mpx.vmhba0:C0:T0:L0
59 9 Corey Osman
virtualdisk 'esxconsole' --size=8004 --onvmfs='datastore1'
60 9 Corey Osman
61 9 Corey Osman
part 'swap'  --fstype=swap --size=1000 --onvirtualdisk='esxconsole'
62 9 Corey Osman
part '/var/log'  --fstype=ext3 --size=2000 --onvirtualdisk='esxconsole'
63 9 Corey Osman
part '/'  --fstype=ext3 --size=5000 --grow --onvirtualdisk='esxconsole'
64 1 Corey Osman
</pre>
65 10 Corey Osman
66 10 Corey Osman
h3. Create a ESX kickstart template in foreman
67 11 Corey Osman
# More-->provisioning Templates-->new
68 11 Corey Osman
# Type: provision
69 11 Corey Osman
# Name: esxi
70 11 Corey Osman
# Use something like the following for the template:
71 11 Corey Osman
<pre>
72 11 Corey Osman
accepteula
73 11 Corey Osman
74 11 Corey Osman
# Canonical drive names:
75 11 Corey Osman
#clearpart --drives=mpx.vmhba0:C0:T0:L0
76 11 Corey Osman
# Uncomment to use first detected disk:
77 11 Corey Osman
#clearpart --firstdisk
78 11 Corey Osman
79 11 Corey Osman
# Uncomment the esxlocation line and comment out the clearpart
80 11 Corey Osman
# and physical partitions to do a non-destructive reinstall.
81 11 Corey Osman
#esxlocation --uuid=881475a6-700a-4b33-aa24-048909df6c14
82 11 Corey Osman
install url <%25= @mediapath %25>
83 11 Corey Osman
84 11 Corey Osman
rootpw --iscrypted <%25= root_pass %25>
85 11 Corey Osman
86 11 Corey Osman
# required for kickstart
87 11 Corey Osman
autopart --firstdisk --overwritevmfs
88 11 Corey Osman
89 11 Corey Osman
# required for kickstart (foreman doesn't do static IPs yet so will need a way to get around this)
90 11 Corey Osman
# if this option is missing the installer will use dhcp
91 11 Corey Osman
#network --addvmportgroup=true --device=vmnic0 --vlanid=127 --bootproto=static --ip=10.0.x.3 --netmask=255.255.255.0 
92 11 Corey Osman
#--gateway=10.0.x.x --nameserver=10.0.x.1,10.0.x.2 --hostname <%25= @host %25>
93 11 Corey Osman
94 11 Corey Osman
95 11 Corey Osman
<%25 if @dynamic -%25>
96 11 Corey Osman
%25include /tmp/diskpart.cfg
97 11 Corey Osman
<%25 else -%25>
98 11 Corey Osman
<%25= @host.diskLayout %25>
99 11 Corey Osman
<%25 end -%25>
100 11 Corey Osman
101 11 Corey Osman
reboot
102 11 Corey Osman
#%25post
103 11 Corey Osman
#/usr/bin/sleep 90
104 11 Corey Osman
# Setup ALUA
105 11 Corey Osman
#/usr/sbin/esxcli nmp satp setdefaultpsp --satp VMW_SATP_ALUA --psp VMW_PSP_RR
106 11 Corey Osman
107 11 Corey Osman
# Create vSwitch0, VMMotion1 and the Service Console port group
108 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -a vSwitch1
109 11 Corey Osman
# Associate vnics to vswitch
110 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -L vmnic2 vSwitch1
111 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -L vmnic3 vSwitch1
112 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -L vmnic1 vSwitch0
113 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -A 10.0.x vSwitch1
114 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -A 10.0.x vSwitch1
115 11 Corey Osman
# configure the VLAN ids if any
116 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -p 10.0.x -v 30 vSwitch1
117 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -p 10.0.x -v 23 vSwitch1
118 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -A VMkernel vSwitch0
119 11 Corey Osman
# configure the VLAN ids if any
120 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -p VMkernel -v 12 vSwitch0
121 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -D "VM Network" vSwitch0
122 11 Corey Osman
# Add a virtual switch
123 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -A "Management Network"  vSwitch0
124 11 Corey Osman
# configure the VLAN ids if any
125 11 Corey Osman
#/usr/sbin/esxcfg-vswitch -p "Management Network" -v 12 vSwitch0
126 11 Corey Osman
# Add VM Kernel Interface
127 11 Corey Osman
#/usr/sbin/esxcfg-vmknic -a -i 10.0.x.x -n 255.255.255.0 "VMkernel"
128 11 Corey Osman
#/usr/sbin/esxcfg-route 10.0.x.x
129 11 Corey Osman
130 11 Corey Osman
# Enable Vmotion on Vkernel
131 11 Corey Osman
#/usr/bin/vmware-vim-cmd hostsvc/vmotion/vnic_set vmk0
132 11 Corey Osman
133 11 Corey Osman
# Inform the build system that we are done.
134 11 Corey Osman
echo "Informing Foreman that we are built"
135 11 Corey Osman
wget -q -O /dev/null --no-check-certificate <%25= foreman_url %25>
136 11 Corey Osman
137 11 Corey Osman
</pre>
138 1 Corey Osman
139 1 Corey Osman
h3. Create a ESX pxe or gpxe template for ESX in foreman
140 12 Corey Osman
# More-->provisioning Templates-->new
141 12 Corey Osman
# Type: pxelinux or gpxe (untested with gpxe)
142 1 Corey Osman
# Name: esxi-pxe
143 13 Corey Osman
# Assign the template to the ESXi operating system that you defined earlier
144 12 Corey Osman
Do not change anything other than the name and location (boot/vmware) of the template.
145 12 Corey Osman
All the files are required and must be in this exact order and with "---" separating each file
146 12 Corey Osman
The files referenced below should be referenced from the root of your tftpboot folder  /var/lib/tftpboot/boot/vmware/
147 12 Corey Osman
148 12 Corey Osman
<pre>
149 12 Corey Osman
150 12 Corey Osman
default ESXi4u1HP-x86_64
151 12 Corey Osman
LABEL ESXi4u1HP-x86_64
152 12 Corey Osman
        kernel /boot/vmware/mboot.c32
153 12 Corey Osman
        MENU LABEL ESXi4u1HP-x86_64        
154 12 Corey Osman
        append boot/vmware/vmkboot.gz 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
155 1 Corey Osman
</pre>
156 13 Corey Osman
157 13 Corey Osman
h3. Additional Steps
158 13 Corey Osman
# Assign the partition table to the ESXi operating system that you defined earlier
159 13 Corey Osman
# Assign the two templates (kickstart, esx-pxe ) to the operating system you defined earlier (more-->operating system-->esx-->templates
160 14 Corey Osman
161 14 Corey Osman
Note:  Currently you will need to staticly assign the network properties in the kickstart each time until foreman can handle these dynamic attributes
162 14 Corey Osman
Note:  This kickstart will overwrite the vmfs volume so please be careful.  
163 14 Corey Osman
Note:  If you remove the the network part the installer will use dhcp and you will need to define your settings after the install.
164 14 Corey Osman
165 14 Corey Osman
Please see the following websites on how to further automate esx settings so your host is ready to go after install
166 14 Corey Osman
167 14 Corey Osman
http://www.virtuallyghetto.com/2010/09/automating-esxi-41-kickstart-tips.html
168 15 Corey Osman
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1012248