VMware Cloud Community
tbowman01
Contributor
Contributor

ESXi 5.1 unattended ks.cfg script to copy and import ova to localhost

I used ESXi Image Builder to create a custom installer with the appropriate drivers needed.  The iso installs as expected.  I have successfully copied files from the CDROM ISO to the local datastore.  I am looking for assistance in how to import the ova file to the localhost (if possible import and poweron) all in the kickstart or first boot.  I have installed the ovftool in ubuntu 12.04, tar and zipped the vmware-ovftool directory to ovftool.tgz.  Placed the file on the cd in the files folder.  Copied files to local datastore but once extracted (manually) it fails to find the ovftool.  I get the error ovftool: not found. 

Below are the configs, any help is appreciated!

Here is the structure of the installer

Custom_ESXi_Installer.iso

--Files

  --vCSA-5.1.ova

  --FutureFiles.ova

  --Scripts

    --config_vcsa.sh

--All the rest of the files for install from the Image Builder

The isolinux.cfg file has been edited to launch the ks.cfg from the root of the cdrom iso.

ie.  append ks=cdrom:/KS.CFG

The boot.cfg file has been changed to the following.

ie. kernelopt=weasel ks=cdrom:/KS.CFG

Here is the kickstart script - KS.CFG:

##############################################    CUSTOM KICKSTART   ##############################################

vmaccepteula

clearpart --alldrives --overwritevmfs

install --firstdisk --overwritevmfs

# test key here

# install --firstdisk --overwritevmfs --esx=11111-22222-33333-44444-55555

# rootpw --iscrypted $1$......

rootpw MySecret123

##############################################    NETWORK   ##############################################

# Can be used to set static host information

# %include /tmp/networkconfig

# network --bootproto=dhcp --device=vmnic0

network --bootproto=static --device=vmnic0 --ip=10.10.0.67 --netmask=255.255.255.0 --gateway=10.10.0.1 --hostname=esxtemp.mydomain.local --nameserver=10.10.0.200 --addvmportgroup=0

##############################################    END NETWORK ##############################################

# commented out for troubleshooting the file copy, extracting, and import of ova via ovftool

# %include /tmp/networkconfig

##############################################    PRE   ##############################################

# not used at this time

# %pre --interpreter=busybox

# VMK_INT="vmk0"

# VMK_LINE=$(localcli network ip interface ipv4 get | grep "${VMK_INT}")

# IPADDR=$(echo "${VMK_LINE}" | awk '{print $2}')

# NETMASK=$(echo "${VMK_LINE}" | awk '{print $3}')

# GATEWAY=$(localcli network ip interface ipv4 list | awk '/default/ {print $3}')

# DNS="10.10.0.200, 10.10.0.1"

# HOSTNAME=$(nslookup "${IPADDR}" | grep Address | awk '{print $4}' | tail -1)

# echo "network --bootproto=static --addvmportgroup=0 --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=${HOSTNAME} > /tmp/networkconfig

##############################################    END PRE  ##############################################

##############################################    POST   ##############################################

%post --interpreter=busybox

# rename local datastore to something to

vim-cmd hostsvc/datastore/rename datastore1 "$(hostname -s)-datastore1"

# copy files to local datastore

# files being copied include ova's, ovftool.tgz, and scripts folder w/myScript.sh

cp -a /vmfs/volumes/CDROM/FILES/* /vmfs/volumes/$(hostname -s)-datastore1/

sleep 10

# test putting this in first boot section

# attempt to extract ovftool.tgz file

# this works manually but cannot find the file consistently when automated - still working on this

# tar zxvf /vmfs/volumes/FILES/OVFTOOL.TGZ -C /vmfs/volumes/$(hostname -s)-datastore1/

# attempt to import and start ova with the ovftool from the esxi shell

# this does not work.  After manually extracting the ovftool.tgz to the datastore1/vmware-ovftool/ovftool

# when executed returns an error ovftool: not found

# --powerOn is optional, could be powered on upon first boot, first need to import/register to localhost

# /vmfs/volumes/$(hostname -s)-datastore1/vmware-ovftool/ovftool --machineOutput --dm=thin --powerOn /vmfs/volumes/$(hostname -s)-datastore1/FILES/VCSA-5.1.ova --name=vCenter vi://root:password@localhost

##############################################   END POST   ##############################################

##############################################   FIRSTBOOT  ##############################################

%firstboot --interpreter=busybox

# assign license

# vim-cmd vimsvc/license --set aaaaa-bbbbb-ccccc-ddddd-eeeee

# disable ipv6

# esxcli network ip set --ipv6-enabled=false

# esxcli system module parameters set -m tcpip3 -p ipv6=0


# enable VHV --no problems with this line

# grep -i "vhv.enable" /etc/vmware/config || echo "vhv.enable = \"TRUE\"" >> /etc/vmware/config

# enable & start remote ESXi Shell (SSH) for troubleshooting only

# vim-cmd hostsvc/enable_ssh

# vim-cmd hostsvc/start_ssh

# enable & start ESXi Shell (TSM) for troubleshooting only

# vim-cmd hostsvc/enable_esx_shell

# vim-cmd hostsvc/start_esx_shell

# ESXi Shell interactive idle time logout

# esxcli system settings advanced set -o /UserVars/ESXiShellInteractiveTimeOut -i 3600

# esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 0

# Block VM guest BPDU packets, global configuration

# esxcli system settings advanced set -o /Net/BlockGuestBPDU -i 1

# Reboot to complete host configuration

esxcli system shutdown reboot -d 60 -r "rebooting after host configurations"

##############################################   END FIRSTBOOT   ##############################################

##############################################   FIRSTBOOT  ##############################################

#

#   Second first boot section, according to the installation script commands document it should be possible to have a second

#   %firstboot section to exectue after the first above essentially 2nd boot?

#

#   Reference: http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.vsphere.install.doc%2FGUID-61A14EBB-...

#

#   Attempt to configure vCSA-5.1.ova presuming the import and poweron was successful above - config_vcsa.sh

#   Reference: http://www.virtuallyghetto.com/2012/09/automating-vcsa-51-vcenter-server.html

#

# TESTING # TESTING # TESTING # TESTING

# Extract ovftool

# tar zxvf /vmfs/volumes/FILES/OVFTOOL.TGZ -C /vmfs/volumes/$(hostname -s)-datastore1/

# TESTING # TESTING # TESTING # TESTING

#

#

# TESTING # TESTING # TESTING # TESTING

# Import ova & poweron VM

# /vmfs/volumes/$(hostname -s)-datastore1/vmware-ovftool/ovftool --machineOutput --dm=thin --powerOn /vmfs/volumes/$(hostname -s)-datastore1/FILES/VCSA-5.1.ova --name=vCenter vi://root:password@localhost

# TESTING # TESTING # TESTING # TESTING

#

#   call config_vcsa.sh from /vmfs/volumes/FILES/SCRIPTS/CONFIG_VCSA.SH

# /vmfs/volumes/FILES/SCRIPTS/CONFIG_VCSA.SH

#

##############################################   END FIRSTBOOT   ##############################################

##  Special Thanks to lamw for the use of his template

Reply
0 Kudos
2 Replies
azlatovic
Contributor
Contributor

Hi!

Just to ask did You ever found answer for this?

It is nice idea.

Struck my mind that maybe you do not have execute bit set on ovftool after untaring. Maybe using tar with xzvpf.

Reply
0 Kudos
sagipael
Contributor
Contributor

i know that this is very long time ago,
but i believe it would help someone in the feature.

the trick is to send the command via ssh (sshpass)
download binary file of sshpass (search online for sshpass binary file, or try take from other linux system)
#add sshpass binary file to /bin/ directory
ln -s /vmfs/volumes/datastore1/Tools/sshpass /bin/sshpass
# add sshpass to /bin/ on boot as well"
echo "ln -s /vmfs/volumes/datastore1/Tools/sshpass /bin/sshpass &" >> /etc/rc.local.d/local.sh

then, send the deploy command via sshpass.. it will work :]

cmd="/vmfs/volumes/datastore1/Tools/vmware-ovftool/ovftool --powerOn -dm=thin -ds=datastore1 -n=$VM_NAME --noSSLVerify $OVA vi://root:$ESXI_PASS@127.0.0.1"
sshpass -p $ESXI_PASS ssh 127.0.0.1 "$cmd"

 

Reply
0 Kudos