Table of Contents
View ghetto profile
As the name suggests, this script allows a user to capture and store some basic configurations from an ESXi host and provides a way to import and apply these configurations to a newly fresh built ESXi host. This script is not meant to be a replacement for VMware's Host Profile, but it provides a simple and free scripted solution for managing stand alone hosts. This is great for a development environment where you may have several configurations and you're rebuilding hosts and don't want to create separate scripts for each. I've personally used this to help rebuild my vESXi (virtual ESXi) hosts for testing different API or script functionalities and with limited resources, I need to consistently rebuild.
The script assumes that your target ESXi host has a bare minimal of networking configured which contains hostname, IP address, gateway, DNS and root password configured. From this, you'll take a profile which has been captured and apply to the target ESXi host and there will be a few areas that will require user input such as configuring a new VMkernel address or removing default portgroups/etc.
Currently this script captures the following basic areas:
Datastore and Storage configurations (includes iSCSI + multipathing)
Network vSwitch + Portgroup configurations
Advanced host setting configurations
There are few limitations such as capturing full iSCSI configurations specifically around CHAP authentication (uni/bi-directional) and I can see why this was a challenge for VMware to included in their current Host Profile offering.
Initial Server Set Up
Supports ESXi (licensed version only)
[vi-admin@scofield profile]$ ./ghettoHostProfile.pl Required command option 'operation' not specified. Required command option 'profile_name' not specified. Synopsis: ./ghettoHostProfile.pl OPTIONS Command-specific options: --operation (required) Operation to perform on host [export|import|dump] --profile_description Description of profile --profile_name (required) Name of the profile Common VI options: --config (variable VI_CONFIG) Location of the VI Perl configuration file --credstore (variable VI_CREDSTORE) Name of the credential store file defaults to <HOME>/.vmware/credstore/vicredentials.xml on Linux and <APPDATA>/VMware/credstore/vicredentials.xml on Windows --encoding (variable VI_ENCODING, default 'utf8') Encoding: utf8, cp936 (Simplified Chinese), iso-8859-1 (German), shiftjis (Japanese) --help Display usage information for the script --passthroughauth (variable VI_PASSTHROUGHAUTH) Attempt to use pass-through authentication --passthroughauthpackage (variable VI_PASSTHROUGHAUTHPACKAGE, default 'Negotiate') Pass-through authentication negotiation package --password (variable VI_PASSWORD) Password --portnumber (variable VI_PORTNUMBER) Port used to connect to server --protocol (variable VI_PROTOCOL, default 'https') Protocol used to connect to server --savesessionfile (variable VI_SAVESESSIONFILE) File to save session ID/cookie to utilize --server (variable VI_SERVER, default 'localhost') VI server to connect to. Required if url is not present --servicepath (variable VI_SERVICEPATH, default '/sdk/webService') Service path used to connect to server --sessionfile (variable VI_SESSIONFILE) File containing session ID/cookie to utilize --url (variable VI_URL) VI SDK URL to connect to. Required if server is not present --username (variable VI_USERNAME) Username --verbose (variable VI_VERBOSE) Display additional debugging information --version Display version information for the script
1. Download the latest Perl Data-Serializer module
2. Upload the tarball to your vMA host
[vi-admin@scofield ~]$ ls Data-Serializer-0.49.tar.gz
3. Extract the tarball contents:
[vi-admin@scofield ~]$ tar -zxvf Data-Serializer-0.49.tar.gz Data-Serializer-0.49/ Data-Serializer-0.49/t/ Data-Serializer-0.49/Changes Data-Serializer-0.49/lib/ Data-Serializer-0.49/MANIFEST Data-Serializer-0.49/META.yml Data-Serializer-0.49/examples/ Data-Serializer-0.49/MANIFEST.SKIP Data-Serializer-0.49/INSTALL Data-Serializer-0.49/README Data-Serializer-0.49/Build.PL .....
4. cd into Data-Serializer folder and create Perl makefile for build process:
[vi-admin@scofield Data-Serializer-0.49]$ perl Makefile.PL # running Build.PL /usr/bin/perl Build.PL Checking whether your kit is complete... Looks good Checking prerequisites... - ERROR: Digest::SHA is not installed * Optional prerequisite YAML is not installed * Optional prerequisite Crypt::Blowfish is not installed * Optional prerequisite Data::Taxi is not installed * Optional prerequisite XML::Dumper is not installed * Optional prerequisite Compress::PPMd is not installed * Optional prerequisite FreezeThaw is not installed * Optional prerequisite XML::Simple is not installed * Optional prerequisite YAML::Syck is not installed * Optional prerequisite JSON::XS is not installed * Optional prerequisite JSON::Syck is not installed * Optional prerequisite Crypt::CBC is not installed * Optional prerequisite Data::Denter is not installed * Optional prerequisite Config::General is not installed * Optional prerequisite JSON is not installed * Optional prerequisite PHP::Serialization is not installed ERRORS/WARNINGS FOUND IN PREREQUISITES. You may wish to install the versions of the modules indicated above before proceeding with this installation Creating new 'Build' script for 'Data-Serializer' version '0.49'
5. Run make test to verify sanity tests succeed before installing:
[vi-admin@scofield Data-Serializer-0.49]$ make test
6. Install the Perl module:
[vi-admin@scofield Data-Serializer-0.49]$ sudo make install
7. Download and upload ghettoHostProfile.pl to your vMA 4.0 host
8. Set the script have execution permission:
[vi-admin@scofield skunkworks]$ chmod +x ghettoHostProfile.pl
Export ghetto profile
You'll want to configured a base ESXi host with all the host related configurations prior to exporting a profile. No changes will be applied when exporting a profile, so you can still have VMs running without anything affecting the host. User's have the option of giving the profile a description by specifying --profile_description, ensure that you wrap the text in quotes if you're going to be using spaces.
Here is the command I'll be using:
[vi-admin@scofield profile]$ ./ghettoHostProfile.pl --server esxi4-1.primp-industries.com --username root --operation export --profile_name esxi4-1_profile --profile_description "development image"
Here is a screenshot of export operation:
Here is a listing of the current directory after the export:
[vi-admin@scofield profile]$ ls -lha total 80K drwxr-xr-x 2 vi-admin root 4.0K Feb 15 19:11 . drwxr-xr-x 8 vi-admin root 4.0K Feb 15 19:11 .. -rw------- 1 vi-admin root 28K Feb 15 19:09 esxi4-1_profile -rw-r--r-- 1 vi-admin root 50 Feb 15 19:09 esxi4-1_profile.md5sum -rwxr-xr-x 1 vi-admin root 38K Feb 15 19:05 ghettoHostProfile.pl
Part of the post-export is to generate an MD5 checksum file against the exported profile to ensure file integrity when importing the profile onto a host. At the end, you'll be left with the profile of the name you specified and a corresponding md5 checksum text file, ensure these are always together when working with this script.
View ghetto profile
If you would like to view the contents of a ghetto profile, you can run the dump operation which creates a a new file named <profilename>.dump
Here is the command I'll be using:
./ghettoHostProfile.pl --server esxi4-2.primp-industries.com --username root --operation dump --profile_name esxi4-1_profile
Here is a screenshot of the dump operation
You can now view the contents of esxi4-1_profile.dump which will show you what was captured from your source ESXi host
Import ghetto profile
The target ESXi host in which the profile will be applied to must be in maintenance mode before any operations are made to ensure you don't have any running VMs/etc. If the host is not in maintenance mode, the user will be prompted and a selection can be made. The script will also prompt the user if he/she would like to take a backup of the existing configuration of the ESXi host, in case there may be some unexpected outcome and you would like to restore the configuration using esxcfg-cfgbackup.
Prior to applying the configurations, the script will verify the md5 checksum file generated earlier in the import and also confirm with the user if he/she would like to proceed.
Here is the command I'll be using:
[vi-admin@scofield profile]$ ./ghettoHostProfile.pl --server esxi4-2.primp-industries.com --username root --operation import --profile_name esxi4-1_profile
Here is a screenshot of the vSphere Client of source ESXi host (esxi4-1.primp-industries.com)
Here is a screenshot of the vSphere Client of target ESXi host (esxi4-2.primp-industries.com) before the profile import:
Here is a screenshot of import operation (highlighted in purple is where user interaction may be required):
If everything goes well, all configuration changes should have been applied and you'll be prompted to issue a reboot to the ESXi host for all changes to take effect.
Here is a screenshot of vSphere Client of target ESXi host (esxi4-2.primp-industries.com) after the profile import: