5 Replies Latest reply on Apr 21, 2017 6:31 PM by Sany_1973

    Script to pre-answer static IP addresses for Auto Deploy hosts (stateless ESXi)

    Enthusiast

      The attached script demonstrates how you can automate bulk addition of stateless ESXi hosts via Auto Deploy with static IP addresses using Host Profile Answer files, as long as you know the primary boot MAC address, or BIOS UUID of the new hosts ahead of time.  The following excerpt from the script describes how this works (refer to the script for more details):

       

       

      # There are two common ways to set up hosts with static IP addresses using Auto
      # Deploy.  The preferred mechanism is to enter static entries within your DHCP
      # server so it always hands out the same IP address to a given MAC address.
      # Then ESX is configured to use DHCP, but will always get the same IP.  This
      # script does not address that approach.  Please refer to your DHCP server
      # documentation for more details on setting this up.
      #
      # The alternative approach is to set up host profiles to use a static IP
      # address and have an answer file for each host that defines its addresses.
      # Normally on first boot, the host will stay in maintenance mode, and require
      # the admin to manually re-apply the profile, at which point you would enter
      # the IP addresses in the GUI which are then stored in the answer file.  This
      # script demonstrates how you can "pre-answer" the static IP settings for hosts
      # so that no user intervention is required on first boot.  The script
      # is structured to facilitate bulk addition of new servers.  As long as you
      # know the MAC address of the primary boot NIC, or the BIOS UUID, then you
      # can run this script to set up all the IP addresses

       

       

       

      Here's what the CSV file might look like, assuming you have two portgroups with vmkernel networking  - "Management Network" and "vmotion"

       

      00:50:56:9c:0e:c8,ESXi-5.0.0-469512-no-tools,MyClusterName,Management Network,192.168.1.10,255.255.255.0,vmotion,192.168.2.10,255.255.255.0

      00:50:56:9c:0e:c9,ESXi-5.0.0-469512-no-tools,MyClusterName,Management Network,192.168.1.11,255.255.255.0,vmotion,192.168.2.11,255.255.255.0

       

      Then running the script (assuming the file above is called "hosts.csv") would look like:

       

      Connect-VIServer MyVcServerName

      Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml

      .\pre-answer.ps1 .\hosts.csv

       

      Once the script completes, you can power on your systems and they'll come up with the desired static IPs automatically without user invervention.

       

      Daniel

        • 2. Re: Script to pre-answer static IP addresses for Auto Deploy hosts (stateless ESXi)
          Bpace Novice

          How could the script be modified to include vLAN ID's?  

          • 3. Re: Script to pre-answer static IP addresses for Auto Deploy hosts (stateless ESXi)
            PrinceBill Lurker

             

            I am new to VMWare ESXi 5.0 Architecture. I have just assembled a PC with i7 3.5 GHz processor installed on ASUS Server board P8BWS

            and have enabled the Intel Bios to Virtualization.

             

            I will appreciate assistance in installing my downloaded ESXi 5.0 Evaluation CD Installation program using an AUTO DEPLOY method

            by specifiying the SCript to look into the USB flash drive for my DHCP Static IP.

             

            My ultimate goal is to be able to create Virtualization and further install Microsoft Server 2008 R2 Server over ESXi 5.0

             

            I have read some threads here about Auto deploy but I am still very confused. I will appreciate a step by step writeup being a novice.

            If a sample AUTO DEPLOY script can be uploaded here - it will be great WHEREBY I can place the SCRIPT in my USB flash drive and have the ESXi 5x installation CD to look into that flash drive and do the following:

             

            1). AUTO CONFIGURE PASSWORD FOR ROOT:
            2). AUTO CONFIGURE DHCP Static IP without user intervention.

             

            A sample script and a step by step write will be appreciated please.

             

            PrinceBill

            • 4. Re: Script to pre-answer static IP addresses for Auto Deploy hosts (stateless ESXi)
              Brian Knutsson Enthusiast
              vExpert

              Hi,

               

              FIXED: This Script only works for normal Virtual Switches, and not for Distributed Switches.

               

              I made a change so that you can use it for Distributed Switches as well.

               

              All you have to do is change this line:

              $propPath.ProfilePath = 'network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-'+$network[0].Replace(",","_").Replace(" ","")+'"].ipConfig'

               

              Into this line:

              $propPath.ProfilePath = 'network.dvsHostNic["key-vim-profile-host-DvsHostVnicProfile-dvSwitch0-'+$network[0].Replace(",","_").Replace(" ","")+'"].ipConfig'

               

              Please notice that dvSwitch0 is hardcoded into this line. I know it is not pretty, but right now I don't have the time, maybe another time.

               

              Also I noticed that you have to put "-vmotion" and "-management" in you answer file after the VMotion portgroup name for it to work. So my answer file lines look like this:

              00:17:A4:AA:BB:CC,ESX5i-20131021-ESXi-5.1.0-20130304001-standard,MANAGEMENT-01,Management-management,10.0.0.10,255.255.255.0,VMotion-0-vmotion,10.0.18.10,255.255.254.0,VMotion-1-vmotion,10.0.19.10,255.255.254.0,ipStorage,10.0.21.10,255.255.255.0

               

              Hope this helps someone.

               

              /Brian.

              • 5. Re: Script to pre-answer static IP addresses for Auto Deploy hosts (stateless ESXi)
                Sany_1973 Enthusiast

                Hi,

                In the script how you get the Key values

                $addr = New-Object VMware.Vim.KeyAnyValue

                               $addr.key = "address"

                               $addr.value = $network[1]

                               $mask = New-Object VMware.Vim.KeyAnyValue

                               $mask.key = "subnetmask"

                               $mask.value = $network[2]

                 

                How can I get the key values for 'PortgroupCreatepolicy'

                 

                Key                            : key-vim-profile-host-VmPortgroupProfile-VMNetwork

                Name                         : VM Network

                Vlan                           : VMware.Vim.VlanProfile

                Vswitch                      : VMware.Vim.VirtualSwitchSelectionProfile

                NetworkPolicy            : VMware.Vim.NetworkPolicyProfile

                Enabled                      : True

                Policy                         : {PortgroupCreatePolicy}

                ProfileTypeName        : VmPortGroupProfile

                ProfileVersion             : 6.0.0

                 

                 

                Thanks.