provisiondevice.sh

Version 2
    Share:|

    Script written for NSH to provision devices within our environment.  Very early step in our automated provisioning.  I'm working on adding error trapping and logging.

     

    syntax:

    ./provisiondevice.sh <MAC> <HOSTNAME> <SERIAL> <ASSET> <PROCESSOR ARCHITECTURE> <VENDOR>

     

    Make sure to change out all of the object IDs

     

     

    #!/bin/nsh

    #This script adds the device to BL and launches the appropriate OS install.

    blcli_setoption serviceProfileName PROD

    blcli_setoption roleName BLAdmins

    blcli_connect

    MAC=$1

    NAME=$2

    SERIAL=$3

    ASSET=$4

    ARCH=$5

    VENDOR=$6

    OS=$7

    PROPFILE=$NAME-$OS_$ARCH_$(date +%m.%d.%y_%H.%M.%S)

    echo "Removing existing devices"

    echo "Adding Device With the following settings: $MAC, $NAME, $SERIAL, $ASSET, $ARCH, $VENDOR", $OS

    # add device to BL set as discovered

    blcli_execute Provision addMacAsDiscovered $MAC

    # set device architecture X86_x64

    blcli_execute ProvisionDevice setPxeDeviceArch $MAC $ARCH

    #set Boot image 306 is boot21_x64 307 is x32

    if [ "$ARCH" = x86 ]

    then

    blcli_execute ProvisionDevice setDeviceBootImage $MAC 307

    else

    blcli_execute ProvisionDevice setDeviceBootImage $MAC 306

    fi

    # set Vendor Property on device options are DELL, IBM, HP, VMWARE

    blcli_execute ProvisionDevice setPropertyValue $MAC VENDOR "$VENDOR"

    blcli_execute ProvisionDevice setPropertyValue $MAC BCBSF_HOST_NAME "$NAME"

    blcli_execute ProvisionDevice setPropertyValue $MAC DESCRIPTION "$NAME"

    blcli_execute ProvisionDevice setPropertyValue $MAC SERIAL_NUMBER "$SERIAL"

    blcli_execute ProvisionDevice setPropertyValue $MAC BCBSF_ASSET_TAG "$ASSET"

    blcli_execute ProvisionDevice setPropertyValue $MAC DESCRIPTION "$NAME"

    echo "$NAME has been imported to Bladelogic and it has been set to discovered."

    echo "# MAKE SURE NO TRAILING OR LEADING WHITESPACE IN VALUE"> /c/temp/$PROPFILE.txt

    echo "SystemPackage.LocalProperty.DATA_STORE=Class://SystemObject/DataStore/Pxe DataStore/PROD_EDC">> /c/temp/$PROPFILE.txt

    echo "Network.DHCPEnabled=true">> /c/temp/$PROPFILE.txt

    echo "Network.AutoDNSEnabled=true">> /c/temp/$PROPFILE.txt

    echo "Job.Provision.JOB_FOLDER_ID=2000866">> /c/temp/$PROPFILE.txt

    echo "Job.Provision.JOB_NAME=$PROPFILE">> /c/temp/$PROPFILE.txt

    if [ $ARCH = x86 ]

    then

    # read $OS

    case $OS in

        W2K3EE ) echo "SystemPackage.LocalProperty.NAME=Windows 2003 Server Enterprise SP-2 (X86)">> /c/temp/$PROPFILE.txt

      blcli_execute Provision provisionDevice 42181 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        W2K3SE ) echo "SystemPackage.LocalProperty.NAME=Windows 2003 Server Standard SP-2 (X86)">> /c/temp/$PROPFILE.txt

        blcli_execute Provision provisionDevice 42182 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        W2K8EE | W2K8SE ) echo "SystemPackage.LocalProperty.NAME=Windows 2008 Enterprise SP2 X86">> /c/temp/$PROPFILE.txt

        blcli_execute Provision provisionDevice 42179 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        W2K8SE ) echo "SystemPackage.LocalProperty.NAME=Windows 2008 Standard SP2 X86">> /c/temp/$PROPFILE.txt

        blcli_execute Provision provisionDevice 42178 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        *) echo "unknown";;

    esac

    else

    # read $OS

    case $OS in

        W2K3EE ) echo "SystemPackage.LocalProperty.NAME=Windows 2003 Server Enterprise SP-2 (x64)">> /c/temp/$PROPFILE.txt

        blcli_execute Provision provisionDevice 42184 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

          W2K8EE) echo "SystemPackage.LocalProperty.NAME=Windows 2008 Enterprise SP2 x64">> /c/temp/$PROPFILE.txt

          blcli_execute Provision provisionDevice 42176 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        W2K8SE ) echo "SystemPackage.LocalProperty.NAME=Windows 2008 Standard SP2 x64">> /c/temp/$PROPFILE.txt

        blcli_execute Provision provisionDevice 42177 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        W2K8R2EE ) echo "SystemPackage.LocalProperty.NAME=Windows 2008 R2 Enterprise x64">> /c/temp/$PROPFILE.txt

        blcli_execute Provision provisionDevice 42101 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        W2K8R2SE ) echo "SystemPackage.LocalProperty.NAME=Windows 2008 R2 Standard x64">> /c/temp/$PROPFILE.txt

        blcli_execute Provision provisionDevice 42111 $MAC 8 file:///c:/temp/$PROPFILE.txt

    ;;

        *) echo "unknown";;

    esac

    fi

    blcli_disconnect

    exit 0