VMware Cloud Community
sportstech
Enthusiast
Enthusiast
Jump to solution

How do I properly call ESXi 4.1 kickstart variables in %firstboot section?

I'm having fits with a new section that I've added to a working kickstart file.  The new section is supposed to retrieve the MAC address for vmnic0 and then grep the MAC address from a file to obtain the server's hostname and other IP addresses.

It successfully sets the MAC address variable, but the other variables do not get set for some reason.  This is verified by the /etc/variables.txt file that I'm writing the values into.  The MAC address is in the file and followed by 4 carriage returns.

So why does calling the variables work in the section with the echo commands but not when used in setting the variables?

########################## BEGIN ks.cfg ##################################
vmaccepteula
autopart --firstdisk=local --overwritevmfs
rootpw --iscrypted 1234567&&&
network --bootproto=dhcp --device=vmnic0 --addvmportgroup=0

# Reboot after installation
reboot

# We will configure some basic things during the first boot from the commandline before we add the host to vCenter
%firstboot --unsupported --interpreter=busybox

# Get IP address info for host
cd /tmp

# Define variables
VMNIC0_MAC=`esxcfg-nics -l |grep vmnic0| awk '{print $7}'`
HOSTNAME=`grep $VMNIC0_MAC vmknic_table | awk -F ";" {'print $1'}`
IPADDR=`grep $HOSTNAME vmknic_table | grep $HOSTNAME | awk -F ";" {'print $2'}`
VMK_VMOTION=`grep $HOSTNAME vmknic_table | grep $HOSTNAME | awk -F ";" {'print $3'}`
VMK_NFS01=`grep $HOSTNAME vmknic_table | grep $HOSTNAME | awk -F ";" {'print $4'}`

echo $VMNIC0_MAC >> /etc/variables.txt
echo $HOSTNAME >> /etc/variables.txt
echo $IPADDR >> /etc/variables.txt
echo $VMK_VMOTION >> /etc/variables.txt
echo $VMK_NFS01 >> /etc/variables.txt

# Configure hostname, IP address, DNS servers, and gateway
vim-cmd hostsvc/net/dns_set --hostname=$HOSTNAME --domainname=ourdomain.net --ip-addresses=10.10.10.1,10.10.10.2 --searchdomain=ourdomain.net
esxcfg-vmknic -i $IPADDR -n 255.255.255.128 "Management Network"
esxcfg-route  10.10.10.129

# Wait to ensure everything has been created and refresh the network stack
sleep 5
vim-cmd hostsvc/net/refresh
########################## END ks.cfg ##################################

########################## BEGIN vmknic_table ###########################
esx01;10.10.10.177;10.10.11.17;10.10.10.17;ce:bf:a2:1f:12:9a
esx02;10.10.10.178;10.10.11.18;10.10.10.18;ce:bf:a2:1f:12:9b
esx03;10.10.10.179;10.10.11.19;10.10.10.19;ce:bf:a2:1f:12:9c
########################## END vmknic_table #############################
Reply
0 Kudos
1 Solution

Accepted Solutions
sportstech
Enthusiast
Enthusiast
Jump to solution

Appears I have fixed my own problem here.

A couple of notes:

First off...in setting my variables, I had some redundant grep commands in there.  Wasn't causing anything to fail, but just making note.

Secondly, the section "network --bootproto=dhcp --device=vmnic0 --addvmportgroup=0" appears to have been the culprit.  I can't say exactly where it was causing my script to fail, but when using DHCP, the server was receiving different DNS servers that caused the script to fail.  I tried using IP addresses instead in my wget line, but it would still fail.  The logs didn't help to clue me in as to why this occurred either.  Quite bizarre.

Anyhow, I decided to just change the line to use a 'dummy' hostname and IP address and then execute an IP address and hostname change later based off of the txt file listing the IP addresses.

View solution in original post

Reply
0 Kudos
6 Replies
moldavite
Contributor
Contributor
Jump to solution

Hi,

Have you tried using the full path to the file?

# Define variables
VMNIC0_MAC=`esxcfg-nics -l |grep vmnic0| awk '{print $7}'`
HOSTNAME=`grep $VMNIC0_MAC /tmp/vmknic_table | awk -F ";" {'print $1'}`
IPADDR=`grep $HOSTNAME /tmp/vmknic_table | grep $HOSTNAME | awk -F ";" {'print $2'}`
VMK_VMOTION=`grep $HOSTNAME /tmp/vmknic_table | grep $HOSTNAME | awk -F ";" {'print $3'}`
VMK_NFS01=`grep $HOSTNAME /tmp/vmknic_table | grep $HOSTNAME | awk -F ";" {'print $4'}`
Reply
0 Kudos
sportstech
Enthusiast
Enthusiast
Jump to solution

Thanks for this suggestion.

It isn't the file that is the issue though as the following worked in my prior kickstart in which I hardcoded the IP address and hostname in the network section. 

VMK_VMOTION=`grep $(hostname) vmknic_table | awk -F ";" {'print $3'}`
VMK_NFS01=`grep $(hostname) vmknic_table | awk -F ";" {'print $4'}`

So to simplify my inquiry, why does calling the hostname command, $(hostname), work just fine though calling the variable, $HOSTNAME, fail?  Is it due to the variables not being sourced when referenced in this manner (between ` ` s)?

Reply
0 Kudos
moldavite
Contributor
Contributor
Jump to solution

Just had a look over some of my build scripts, any chance you can give this a go

# Define variables
VMNIC0_MAC=`esxcfg-nics -l |grep vmnic0| awk '{print $7}'`
HOSTNAME=$(grep $VMNIC0_MAC vmknic_table | awk -F ";" {'print $1'})
IPADDR=$(grep $HOSTNAME vmknic_table | grep $HOSTNAME | awk -F ";" {'print $2'})
VMK_VMOTION=$(grep $HOSTNAME vmknic_table | grep $HOSTNAME | awk -F ";" {'print $3'})
VMK_NFS01=$(grep $HOSTNAME vmknic_table | grep $HOSTNAME | awk -F ";" {'print $4'})
Reply
0 Kudos
sportstech
Enthusiast
Enthusiast
Jump to solution

Tried that as well and that format is unsuccessful as well.

I even tried the following no to avail.  I just can't figure why the VMNIC0_MAC variable succeeds and I can't get the others to.

HOSTNAME=`grep $(esxcfg-nics -l |grep vmnic0| awk '{print $7}') vmknic_table | awk -F ";" {'print $1'}`

Reply
0 Kudos
sportstech
Enthusiast
Enthusiast
Jump to solution

Still not having success.

What would actually be ideal is getting all of the variables and passing them into the network section.

Example:

network --bootproto=static --device=vmnic0 --hostname=$HOSTNAME --ip=$IPADDR --gateway=10.10.10.129 --nameserver=10.10.10.9 --netmask=255.255.255.128 --addvmportgroup=0

can this line exist in the %firstboot section of the kickstart file?
Reply
0 Kudos
sportstech
Enthusiast
Enthusiast
Jump to solution

Appears I have fixed my own problem here.

A couple of notes:

First off...in setting my variables, I had some redundant grep commands in there.  Wasn't causing anything to fail, but just making note.

Secondly, the section "network --bootproto=dhcp --device=vmnic0 --addvmportgroup=0" appears to have been the culprit.  I can't say exactly where it was causing my script to fail, but when using DHCP, the server was receiving different DNS servers that caused the script to fail.  I tried using IP addresses instead in my wget line, but it would still fail.  The logs didn't help to clue me in as to why this occurred either.  Quite bizarre.

Anyhow, I decided to just change the line to use a 'dummy' hostname and IP address and then execute an IP address and hostname change later based off of the txt file listing the IP addresses.

Reply
0 Kudos