SovLabs Support

Submit a Ticket My Tickets
Welcome
Login

Using Lifecycle Toolkit to run multiple scripts dynamically

 

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 http://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 DefinitionData Type
      Add_RDP_UserBoolean
      Add_create_fileBoolean


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

      Custom PropertyScript Description
      script_add_RDP_UserScript to use for adding the requested user to the local RDP user group
      script_create_fileScript to create a file in the C:\windows\temp 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 http://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



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 NameConfiguration Value
      Configuration Labelscript_execute
      TypeProvisioned Node
      OS Familywindows
      Connection Typevmware-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 DirectoryC:\Windows\Temp

  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 NameConfiguration 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

    LineValuation StartDescriptionValue AssignmentDescriptionValue AssignmentDescriptionValuation EndDescription
    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 executeStart-Sleep -s 30powershell 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 executeStart-Sleep -s 30powershell 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 NameConfiguration Value
    Configuration Labelscript_runner
    Machine Provisioned PRE Scriptsscript_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 http://docs.sovlabs.com/latest/vRA/7.5/modules/vra-toolkits/lifecycle-toolkit/







 


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.