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
- In vRA navigate to Administration>Property Dictionary>Property Definitions
- For each powershell script, create a Property Definition to determine whether or not they should be ran
-
Examples
Property DefinitionData TypeAdd_RDP_UserBooleanAdd_create_fileBoolean -
Create a Property Group and assign the properties inside it with the values being the script code to be executed
Custom PropertyScript Descriptionscript_add_RDP_UserScript to use for adding the requested user to the local RDP user groupscript_create_fileScript to create a file in the C:windowstemp directory
-
Assign Properties to the blueprint(s)
- In vRA navigate to Design>Blueprints
- Edit the Windows blueprint that will utilize the script choices
- Select the component(s) in the blueprint and add the Custom Properties. Be sure to have the “Show in Request” checkbox selected
- Edit the Windows blueprint that will utilize the script choices
Create your Lifecycle EBS
- 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.
- 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
- In vRA navigate to the Catalog then search and execute the Add Lifecycle Script Definition catalog item
- Enter in the following information
-
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
-
-
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 - Click submit to and create the script definition
Create Lifecycle Profile
- In vRA navigate to the Catalog then search and execute the Add Lifecycle Profile catalog item
- Enter in the following information
-
Configuration Details
Configuration NameConfiguration ValueConfiguration Labelscript_runnerMachine Provisioned PRE Scriptsscript_execution - 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)
- In vRA navigate to Design>Blueprints
- Edit the blueprint that contains the custom properties modified in the earlier steps
- Add the Property Group to the component(s)
- Property Group List
- Scripts
- SovLabs_LCProfile-%tenantname%_script_runner
- Property Group List
Confirm selections to utilize the new scripts are available in the blueprint build screen
- In vRA navigate to Catalog and request the target blueprint which was modified in the previous steps
- 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 %}