Project

General

Profile

VMware ESXi » History » Version 22

Michael Welle, 03/24/2016 04:20 AM

1 1 Corey Osman
h1. How to Provision a VMware ESXi server using foreman
2 1 Corey Osman
3 20 Jochen Schalanda
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 20 Jochen Schalanda
7 1 Corey Osman
# Copy iso contents of ESXi to your media directory
8 1 Corey Osman
# Copy the esx boot files to your tftp directory
9 8 Corey Osman
# Create a ESX Installation Medium in Foreman
10 20 Jochen Schalanda
# Create a ESX operating system in Foreman
11 1 Corey Osman
# Create a ESX partition table (optional) template
12 1 Corey Osman
# Create a ESX kickstart template in foreman
13 20 Jochen Schalanda
# Create a ESX pxe or gpxe template for ESX in Foreman
14 1 Corey Osman
15 1 Corey Osman
16 20 Jochen Schalanda
h3. Copy ISO contents of ESXi to your media directory (example only)
17 20 Jochen Schalanda
18 1 Corey Osman
<pre>
19 6 Corey Osman
mkdir /mnt/iso1
20 6 Corey Osman
mkdir -p /var/www/html/repos/vmware/esxi4.1/  
21 5 Corey Osman
mount -o loop esxi-iso-file.iso /mnt/iso1  (example for RHEL based distros)
22 1 Corey Osman
rsync -avz /mnt/iso1/ /var/www/html/repos/vmware/esxi4.1/
23 4 Corey Osman
</pre>
24 4 Corey Osman
25 4 Corey Osman
h3. Copy the esx boot files to your tftp directory  (must have all of these)
26 20 Jochen Schalanda
27 4 Corey Osman
<pre>
28 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/mboot.c32 /var/lib/tftpboot/boot/vmware/
29 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/vmkboot.gz /var/lib/tftpboot/boot/vmware/
30 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/vmkernel.gz /var/lib/tftpboot/boot/vmware/
31 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/sys.vgz /var/lib/tftpboot/boot/vmware/
32 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/cim.vgz /var/lib/tftpboot/boot/vmware/
33 1 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/ienviron.vgz /var/lib/tftpboot/boot/vmware/
34 4 Corey Osman
cp /var/www/html/repos/vmware/esxi4.1/install.vgz /var/lib/tftpboot/boot/vmware/
35 4 Corey Osman
</pre>
36 2 Corey Osman
37 8 Corey Osman
h3. Create the installation medium based on where you put your esx4.1 iso contents
38 20 Jochen Schalanda
39 9 Corey Osman
# Create new medium
40 1 Corey Osman
# vmware
41 9 Corey Osman
# path: http://192.168.1.88/repos/vmware/esxi$version/  (example only)
42 9 Corey Osman
# OS: ESXi4.1  (can define later after making operating system)
43 9 Corey Osman
44 9 Corey Osman
h3. Create a ESX operating system in foreman (Example only)
45 20 Jochen Schalanda
46 8 Corey Osman
# More-->Operating Systems-->New
47 8 Corey Osman
# Name: ESXi
48 8 Corey Osman
# Major: 4
49 8 Corey Osman
# Minor 1
50 8 Corey Osman
# OS Family: Redhat (there is no vmware yet)
51 1 Corey Osman
# Arch: x86_64
52 8 Corey Osman
# Choose any partition tables if you defined any (can do later)
53 8 Corey Osman
# Choose the vmware installation media (can do later) 
54 1 Corey Osman
55 1 Corey Osman
h3. Create a Partition table in Foreman (optional)
56 20 Jochen Schalanda
57 1 Corey Osman
# Name: esxi4.1 (name whatever you need to)
58 13 Corey Osman
# Assign the template to the ESXi operating system that you defined earlier
59 9 Corey Osman
# Layout:  (Something like the following)
60 9 Corey Osman
<pre>
61 9 Corey Osman
part '/boot'  --fstype=ext3 --size=1100  --ondisk=mpx.vmhba0:C0:T0:L0
62 9 Corey Osman
part 'none'  --fstype=vmkcore --size=110  --ondisk=mpx.vmhba0:C0:T0:L0
63 9 Corey Osman
part 'datastore1'  --fstype=vmfs3 --size=9004 --grow  --ondisk=mpx.vmhba0:C0:T0:L0
64 9 Corey Osman
virtualdisk 'esxconsole' --size=8004 --onvmfs='datastore1'
65 9 Corey Osman
66 9 Corey Osman
part 'swap'  --fstype=swap --size=1000 --onvirtualdisk='esxconsole'
67 1 Corey Osman
part '/var/log'  --fstype=ext3 --size=2000 --onvirtualdisk='esxconsole'
68 9 Corey Osman
part '/'  --fstype=ext3 --size=5000 --grow --onvirtualdisk='esxconsole'
69 9 Corey Osman
</pre>
70 1 Corey Osman
71 10 Corey Osman
h3. Create a ESX kickstart template in foreman
72 20 Jochen Schalanda
73 11 Corey Osman
# More-->provisioning Templates-->new
74 11 Corey Osman
# Type: provision
75 11 Corey Osman
# Name: esxi
76 11 Corey Osman
# Use something like the following for the template:
77 11 Corey Osman
<pre>
78 16 Corey Osman
vmaccepteula
79 1 Corey Osman
80 22 Michael Welle
install url <%= @mediapath %>
81 16 Corey Osman
# Set the root password for the DCUI and Tech Support Mode
82 22 Michael Welle
rootpw --iscrypted <%= root_pass %>
83 11 Corey Osman
84 11 Corey Osman
# required for kickstart
85 11 Corey Osman
autopart --firstdisk --overwritevmfs
86 11 Corey Osman
87 16 Corey Osman
# Set the network to DHCP on the first network adapater
88 16 Corey Osman
network --bootproto=dhcp --device=vmnic0
89 16 Corey Osman
90 11 Corey Osman
# required for kickstart (foreman doesn't do static IPs yet so will need a way to get around this)
91 11 Corey Osman
# if this option is missing the installer will use dhcp
92 1 Corey Osman
#network --addvmportgroup=true --device=vmnic0 --vlanid=127 --bootproto=static --ip=10.0.x.3 --netmask=255.255.255.0 
93 22 Michael Welle
#--gateway=10.0.x.x --nameserver=10.0.x.1,10.0.x.2 --hostname <%= @host %>
94 11 Corey Osman
95 11 Corey Osman
96 22 Michael Welle
<% if @dynamic -%>
97 22 Michael Welle
%include /tmp/diskpart.cfg
98 22 Michael Welle
<% else -%>
99 22 Michael Welle
<%= @host.diskLayout %>
100 22 Michael Welle
<% end -%>
101 1 Corey Osman
102 16 Corey Osman
# A sample post-install script
103 22 Michael Welle
%post --unsupported --ignorefailure=true
104 11 Corey Osman
105 11 Corey Osman
# Inform the build system that we are done.
106 11 Corey Osman
echo "Informing Foreman that we are built"
107 22 Michael Welle
wget -q -O /dev/null --no-check-certificate <%= foreman_url %>
108 11 Corey Osman
109 19 Corey Osman
# Configure additional commands at first boot.
110 22 Michael Welle
%firstboot --unsupported --interpreter=busybox
111 19 Corey Osman
# Setup VMotion portgroup on vSwitch0
112 19 Corey Osman
esxcfg-vswitch -A VMotion vSwitch0
113 19 Corey Osman
# Setup VMotion IP address
114 19 Corey Osman
esxcfg-vmknic -a VMotion -i [VMKIPADDR] -n 255.255.255.0
115 19 Corey Osman
# Wait for previous command to finish before enabling VMotion
116 19 Corey Osman
sleep 10
117 19 Corey Osman
# Enable VMotion (ESX uses vmware-vim-cmd and ESXi is vim-cmd)
118 1 Corey Osman
vim-cmd hostsvc/vmotion/vnic_set vmk1
119 19 Corey Osman
vim-cmd hostsvc/net/refresh
120 19 Corey Osman
</pre>
121 11 Corey Osman
122 11 Corey Osman
h3. Create a ESX pxe or gpxe template for ESX in foreman
123 20 Jochen Schalanda
124 1 Corey Osman
# More-->provisioning Templates-->new
125 12 Corey Osman
# Type: pxelinux or gpxe (untested with gpxe)
126 12 Corey Osman
# Name: esxi-pxe
127 1 Corey Osman
# Assign the template to the ESXi operating system that you defined earlier
128 13 Corey Osman
Do not change anything other than the name and location (boot/vmware) of the template.
129 12 Corey Osman
All the files are required and must be in this exact order and with "---" separating each file
130 12 Corey Osman
The files referenced below should be referenced from the root of your tftpboot folder  /var/lib/tftpboot/boot/vmware/
131 12 Corey Osman
132 12 Corey Osman
<pre>
133 12 Corey Osman
default ESXi4u1HP-x86_64
134 12 Corey Osman
LABEL ESXi4u1HP-x86_64
135 1 Corey Osman
        kernel /boot/vmware/mboot.c32
136 1 Corey Osman
        MENU LABEL ESXi4u1HP-x86_64        
137 22 Michael Welle
        append boot/vmware/vmkboot.gz ks=<%= foreman_url("provision")%> --- boot/vmware/vmkernel.gz --- boot/vmware/sys.vgz --- boot/vmware/cim.vgz --- boot/vmware/ienviron.vgz --- boot/vmware/install.vgz
138 1 Corey Osman
</pre>
139 1 Corey Osman
140 1 Corey Osman
h3. Additional Steps
141 20 Jochen Schalanda
142 1 Corey Osman
# Assign the partition table to the ESXi operating system that you defined earlier
143 13 Corey Osman
# Assign the two templates (kickstart, esx-pxe ) to the operating system you defined earlier (more-->operating system-->esx-->templates
144 13 Corey Osman
145 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
146 20 Jochen Schalanda
* Note:  This kickstart will overwrite the vmfs volume so please be careful.  
147 20 Jochen Schalanda
* Note:  If you remove the the network part the installer will use dhcp and you will need to define your settings after the install.
148 20 Jochen Schalanda
149 14 Corey Osman
Please see the following websites on how to further automate esx settings so your host is ready to go after install
150 14 Corey Osman
151 14 Corey Osman
* "Automating ESXi 4.1 Kickstart Tips & Tricks":http://www.virtuallyghetto.com/2010/09/automating-esxi-41-kickstart-tips.html
152 20 Jochen Schalanda
* "PXE and kickstart on ESX 4.x":http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1012248
153 20 Jochen Schalanda
* "Vmware Kickstart Options -- Page 35":http://www.vmware.com/pdf/vsphere4/r41/vsp_41_esxi_i_vc_setup_guide.pdf
154 22 Michael Welle
* "ESXi 5.x/6.x deployment with Foreman":http://www.c0t0d0s0.de/esxwithforeman/esxwithforeman.html