1 Reply Latest reply on Jan 10, 2011 7:21 AM by msemon1

    Building a host from a script

    pauljawood Enthusiast



      I'm looking for a way that is scripted for building a host that will prompt for the host name, ip information. This is for ESX and ESXi (4.1) and I have a script to join the newly built hosts to cluster and apply host profiles and dvswitchs.


      Replacing an old 3.5 build system that will not support the new 4.1 infrastructure and any suggestions are greatly appreciated.

        • 1. Re: Building a host from a script
          msemon1 Expert

          Creating an automated script for ESXi is a little different since it it does not have the full Service Console and the partitioning the ESX requires.

          Here is the kickstart script I use. The one problem I have run into is getting the NIC Teaming policy to set correctly. Also I have been unable to set the default gateway for the VMotion network. I was told only one default gateway could be set in script and that you have to set that maually.

          The nice feature about the new kickstart script is the dryrun feature which allows you to check your script.



          rootpw your secret password
          autopart --firstdisk --overwritevmfs

          #Network install type
          network --bootproto=static --addvmportgroup=false --device=vmnic0 --ip=10.x.x.x --netmask= --gateway=10.x.x.x  --nameserver=10.x.x.x,10.x.x.x --hostname=Server FQDN


          %firstboot --unsupported --interpreter=busybox --level=998

          #Add vMotion Portgroup to vSwitch0
          esxcfg-vswitch -A vMotion vSwitch0

          #Assign VLAN to Management PortGroup
          esxcfg-vswitch -v 10 -p 'Management Network' vSwitch0

          #Add pNIC vmnic1 to vSwitch0
          esxcfg-vswitch -L vmnic1 vSwitch0

          #Assign ip address to vMotion vmk1
          esxcfg-vmknic -a -i 10.x.x.x -n -p vMotion
          esxcfg-vmknic -e vMotion

          #Assign VLAN to vMotion PortGroup
          esxcfg-vswitch -v 20 -p vMotion vSwitch0

          sleep 10

          #set vMotion to vmk
          vim-cmd hostsvc/vmotion/vnic_set vmk1

          #Set NIC order policy for port groups
          vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-active=vmnic0 --nicorderpolicy-standby=vmnic1 vSwitch0 'Management Network'

          vim-cmd hostsvc/net/portgroup_set --nicorderpolicy-active=vmnic1 --nicorderpolicy-standby=vmnic0 vSwitch0 vMotion

          #Add new vSwitch for Virtual Machine Network
          esxcfg-vswitch -a vSwitch1

          #Add Virtual Machine Network Portgroup to vSwitch1
          esxcfg-vswitch -A 'Virtual Machine Network' vSwitch1

          #Add pNIC vmnic2 to vSwitch1
          esxcfg-vswitch -L vmnic2 vSwitch1

          #Add pNIC vmnic3 to vSwitch1
          esxcfg-vswitch -L vmnic3 vSwitch1

          #Assign VLAN to Virtual Machine PortGroup
          esxcfg-vswitch -v 30 -p 'Virtual Machine Network' vSwitch1

          #Add new vSwitch for DMZ
          esxcfg-vswitch -a vSwitch2

          #Add DMZ Portgroup to vSwitch2
          esxcfg-vswitch -A DMZ vSwitch2

          #Add pNIC vmnic4 to vSwitch2
          esxcfg-vswitch -L vmnic4 vSwitch2

          #Add pNIC vmnic5 to vSwitch2
          esxcfg-vswitch -L vmnic5 vSwitch2

          #Assign VLAN to Virtual Machine PortGroup
          esxcfg-vswitch -v 9 -p DMZ vSwitch2

          vim-cmd hostsvc/net/vswitch_setpolicy -–nicteaming-policy=loadbalance_ip vSwitch0
          vim-cmd hostsvc/net/vswitch_setpolicy -–nicteaming-policy=loadbalance_ip vSwitch1
          vim-cmd hostsvc/net/vswitch_setpolicy -–nicteaming-policy=loadbalance_ip vSwitch2
          vim-cmd hostsvc/net/portgroup_set --nicteaming-policy=loadbalance_ip vSwitch0 "Management Network"
          vim-cmd hostsvc/net/portgroup_set --nicteaming-policy=loadbalance_ip vSwitch0 vMotion
          vim-cmd hostsvc/net/portgroup_set --nicteaming-policy=loadbalance_ip vSwitch1 "Virtual Machine Network"
          vim-cmd hostsvc/net/portgroup_set --nicteaming-policy=loadbalance_ip vSwitch2 DMZ 

          vim-cmd hostsvc/net/refresh

          sleep 10

          # NTP time config
          echo "Configuring NTP"
          echo restrict default kod nomodify notrap noquerynopeer > /etc/ntp.conf
          echo restrict >> /etc/ntp.conf
          echo server NTP server FQDN >> /etc/ntp.conf
          echo driftfile /var/lib/ntp/drift >> /etc/ntp.conf
          /sbin/chkconfig –-level 345 ntpd on
          /etc/init.d/ntpd stop
          /etc/init.d/ntpd start

          #enable SSH TechSupportMode
          vim-cmd hostsvc/enable_remote_tsm
          vim-cmd hostsvc/start_remote_tsm

          vim-cmd hostsvc/enable_local_tsm
          vim-cmd hostsvc/start_local_tsm