Sometimes you might run into a case (hopefully you don’t!) where a plugin needs to be installed on each ESXi host, but there’s no Update Manager instance handy to pass this out. I dealt with this situation recently by writing a couple of scripts to be run from a vMA that has targeted the vCenter server. It will go out and SCP the files to the host, then install the VIB. Sadly, the plugin didn’t get to stay. On the bright side, I got to generate an uninstall script as well! Below are both scripts. You run them in this fashion:
./install_vib.sh [vCenter server] [file with one host per line.txt]
They aren’t super robust, so make sure your inputs are right!
[code language=”bash”] #!/bin/bash# run this script from vMA in this fashion: ./script.sh [vCenter Server] [file with on ESXi host on each line]
# validate that input has two parameters
if [ $# -ne 2 ]; then
echo "$0 [VCENTER] [HOSTS_FILE]"
exit 1
fi
# assign input args and username
VCENTER_HOST=$1
HOSTLIST=$2
export VI_USERNAME=root
# target vCenter server
source /opt/vmware/vma/bin/vifptarget -s ${VCENTER_HOST} > /dev/null 2>&1
echo -n "Now connected to: "
source /opt/vmware/vma/bin/vifptarget -d
# take inputs interactively
read -p "Enter VIB name: " VIB_NAME
read -p "Enter full .zip path on vMA: " VIB_PATH
read -s -p "Enter root password: " VI_PASSWORD ; export VI_PASSWORD
# show hosts to operate on
echo "Installing VIB on :"
cat $HOSTLIST
# SCP software, then install
if [ $? -eq 0 ]; then
IFS=$’n’ #one host to a line in the .txt file
for VI_HOST in $(cat ${HOSTLIST});
do
echo "Copying .zip files for ${VI_HOST}…"
echo "Enter password for ‘root’ to SCP file."
scp ${VIB_PATH} root@${VI_HOST}:/opt/$VIB_NAME.zip
echo "Installing VIB for ${VI_HOST}…"
esxcli –server ${VI_HOST} software vib install -n $VIB_NAME -d file:///opt/$VIB_NAME.zip
echo
done
unset IFS
else
echo "Unable to intialize installation.}"
fi
echo "Installation process complete."
[/code]
And to uninstall:
[code language=”bash”] #!/bin/bash# run this script from vMA in this fashion: ./script.sh [vCenter Server] [file with on ESXi host on each line]
# validate that input has two parameters
if [ $# -ne 2 ]; then
echo "$0 [VCENTER] [HOSTS_FILE]"
exit 1
fi
# assign input args and username
VCENTER_HOST=$1
HOSTLIST=$2
export VI_USERNAME=root
# target vCenter server
source /opt/vmware/vma/bin/vifptarget -s ${VCENTER_HOST} > /dev/null 2>&1
echo -n "Now connected to: "
source /opt/vmware/vma/bin/vifptarget -d
# take inputs interactively
read -p "Enter VIB name: " VIB_NAME
read -s -p "Enter root password: " VI_PASSWORD ; export VI_PASSWORD
# show hosts to operate on
echo "Uninstalling VIB on :"
cat $HOSTLIST
# Uninstall software
if [ $? -eq 0 ]; then
IFS=$’n’ # one host to a line in the .txt file
for VI_HOST in $(cat ${HOSTLIST});
do
echo "Uninstalling VIB for ${VI_HOST}…"
esxcli –server ${VI_HOST} software vib remove -n $VIB_NAME
echo
done
unset IFS
else
echo "Unable to intialize uninstallation.}"
fi
echo "Uninstallation process complete."
[/code]
Also, I’m not sure exactly where it came from since this was a couple of weeks ago, but I remember that I cannibalized some of this from something William Lam (@lamw) had previously written. So all credit to him for doing a lot of the legwork!