Can Cruz pass an attribute value from an Action script to another Action script?

This article describes how to set up action scripts so you can take the extracted value of one script and pass it to another action script

Yes, there are many use cases where the output for an action command contains data you may need before you can execute a subsequent action. Rather than run 2 independent actions, you can to run a single action that first invokes the action to get the data and then the second to pass the data to the second action script.

A use case example would be starting or stopping a process using PowerShell. Typically, you would need to execute a script to get the process name or PID then run a separate script to kill the PID number. With this enhancement, you can have the following: 

      • Script 1 - Gets PID from a specific process and extracts the PID value.  
      • Script 2 - Is set to run script 1 first, and the PID value is then inserted into script 2 where needed. (i.e., kill PID#) 
      • You only run script 2, and the desired process is terminated.   

NOTE: Script 1 needs to execute against the specified target, or the parent action, without user-specified attributes. 

This action can be set up for any managed device with a command line interface. The example below is executed against an ESX server and uses esxcli to first extract a list from esx (Action esxcli - Extract vSwitch List)  and the pass the Virtual switch name to action esxcli - Add Port Group to Switch 

Here are the steps to setup this type of action . These Actions in this example are also seeded in Cruz Version 10 and later.

NOTE: this is for advanced user who already have experience with creating and executing action. Please review our other action tutorial if you are not familiar with Actions 

#1 Create the action to extract the needed data (esxc1li - Extract vSwitch List). In the attribute settings tab, you can create a variety of attribute types. In this case a simple string attribute will be used hold the "Virtual switch List".  Save it and go to Scripts,

Here you can enter the script. Go to the Value extraction Tab

In the Value Extraction tab, you can use Regex to extract data from the output

Note: The small shield in the upper right corner will allow you to test the regex

Apply and save

#2 Create the action that requires the extracted value (esxcli - Add Port Group to Switch)

There are 2 attributes for this script 

Port-group Name - Is a string value and will be entered by the user

Virtual Switch Name - Is also a string value but will be pre-populated by executing script from step 1. Go to the Advance tab

In the advanced tab, we can set the action that provide the data 

And the Value Attribute specifies the attribute from the source script and is mapped to "Virtual switch name" in this action script 

Apply and save

To execute simply run the second script and these steps occur"

1. script 1 executes first and extracts the Virtual Switch List

2. script 2 runs and inserts the extracted attribute into its script

In this case the attribute is a list of Virtual switches and the user set the port group name 

and then select an item from the vSwitch lists

 

An example: The resulting command that get executed on the target is:

esxcli network vSwitch standard portgroup add -p MyPortgroupName -v MySelectedvSwitch