Overview

The below guide will describe a use-case of executing multiple powershell scripts using Lifecycle Toolkit based on dynamic entries from a blueprint form.

 

Considerations

This guide is built for Powershell script execution, however this could be followed similarly for unix based commands. This also assumes you have already created your vRACafe Host prerequisite per the setup instructions found at https://docs.sovlabs.com/latest/vRA/7.5/modules/vra-toolkits/lifecycle-toolkit/setup/

For Windows scripts, UAC (User Account Control) policies may block script execution. Modification to your template may be necessary to execute the scripts successfully.

 

Test Scenario

Sovlabs Plugin Version: 2018.3.4

vRealize Version: 7.5

 

Procedure

Prepare your On/Off properties and script properties
  1. In vRA navigate to Administration>Property Dictionary>Property Definitions
  2. For each powershell script, create a Property Definition to determine whether or not they should be ran
    1. Examples

      Property Definition
      Data Type
      Add_RDP_User
      Boolean
      Add_create_file
      Boolean

       

    2. Create a Property Group and assign the properties inside it with the values being the script code to be executed

      Custom Property
      Script Description
      script_add_RDP_User
      Script to use for adding the requested user to the local RDP user group
      script_create_file
      Script to create a file in the C:windowstemp directory

 

Assign Properties to the blueprint(s)
  1. In vRA navigate to Design>Blueprints
    1. Edit the Windows blueprint that will utilize the script choices
      1. Select the component(s) in the blueprint and add the Custom Properties. Be sure to have the “Show in Request” checkbox selected

 

Create your Lifecycle EBS
  1. Per https://docs.sovlabs.com/latest/vRA/7.5/modules/vra-toolkits/lifecycle-toolkit/setup/ – follow the Add Lifecycle EBS documentation to create a EBS.
  2. In this example I have used the Machine Provisioned lifecycle state with a priority as the last item ran in the build process before completion

{% raw %}

 

Create Lifecycle Script Definition
  1. In vRA navigate to the Catalog then search and execute the Add Lifecycle Script Definition catalog item
  2. Enter in the following information
    1. Configuration Details

      Configuration Name Configuration Value
      Configuration Label script_execute
      Type Provisioned Node
      OS Family windows
      Connection Type vmware-tools
      vCenter Endpoint (enter in the vCenter endpoint connection)
      Credentials (create credential used for the local VM that has the ability to execute scripts)
      Default EBS (select the EBS created from the previous step)
      Interpreter (Script type) Powershell
      Script Temporary Directory C:WindowsTemp

  3. For the script textbox, we inserted custom decision/dynamic execution code. The below table will help guide how we come to the final code

    Configuration Name Configuration Value
    Script

    {% if Add_RDP_User == ‘true’ %}{{script_add_RDP_User}}Start-Sleep -s 30{% endif %}

    {% if Add_create_file == ‘true’ %}{{script_create_file}}Start-Sleep -s 30{% endif %}

      

    Script Code Breakdown

    Line Valuation Start Description Value Assignment Description Value Assignment Description Valuation End Description
    1 {% if Add_RDP_User == ‘true’ %} if statement to determine if the value of “Add_RDP_User” is true {{script_add_RDP_User}} Insert the property value which has the Powershell script itself to execute Start-Sleep -s 30 powershell command to start a sleep/wait of 30 seconds. This can be less or more as needed {% endif %} ends if statement
    2 {% if Add_create_file == ‘true’ %} if statement to determine if the value of “Add_create_file” is true {{script_create_file}} Insert the property value which has the Powershell script itself to execute Start-Sleep -s 30 powershell command to start a sleep/wait of 30 seconds. This can be less or more as needed {% endif %} ends if statement
                     
  4. Click submit to and create the script definition

 

Create Lifecycle Profile
  1. In vRA navigate to the Catalog then search and execute the Add Lifecycle Profile catalog item
  2. Enter in the following information
  3. Configuration Details

    Configuration Name
    Configuration Value
    Configuration Label
    script_runner
    Machine Provisioned PRE Scripts
    script_execution

  4. Submit the catalog item. This will create the SovLabs_LCProfile-%tenantname%_script_runner property group

 

Apply the Lifecycle and Scripts Property Group to the Blueprint(s)
  1. In vRA navigate to Design>Blueprints
  2. Edit the blueprint that contains the custom properties modified in the earlier steps
  3. Add the Property Group to the component(s)
    1. Property Group List
      1. Scripts
      2. SovLabs_LCProfile-%tenantname%_script_runner

 

Confirm selections to utilize the new scripts are available in the blueprint build screen
  1. In vRA navigate to Catalog and request the target blueprint which was modified in the previous steps
  2. Confirm that in the component section that the 2 custom property fields are selectable

 

Additional information

Lifecycle Toolkit Documentation can be found at https://docs.sovlabs.com/latest/vRA/7.5/modules/vra-toolkits/lifecycle-toolkit/ {% endraw %}

Recommended Reading