How to use Input Arrays with ABX Actions.
Don’t automate for the sake of automation—automate to simplify, accelerate, and improve.
Note: VCF Automation 8.18.1 was used to create this Blog
I recently received a question about leveraging an Array Input from a VCF Automation Template and processing the array data within an ABX Action. Below, you’ll find example code and screenshots demonstrating the approach. If you’re working with array inputs in your automation workflows, this guide should be helpful!
Screenshots demonstrating the use of VCF Automation Input Arrays:
- Example manual Deployment that has an Array Input
- Example Custom Form using an Array Input
Screen Shot of the YAML Code for Input Array:
- Define the input type as array
- Use the array input in the “Cloud.vSphere.Machine” - “properties:” section
- All properties values will get passed in the ABX Action
Screen Shot of the Inputs:
- If you haven’t worked with YAML array inputs before, use the Inputs screens in VCF Automation to assist in formatting the YAML correctly. This will ensure the data is structured properly before being passed to the ABX Action.
Screen Shot of the Array Creation with Inputs:
- Example screen of creating an Array
Screen Shot of the Subscription to execute an ABX Action during an VM Build:
- In this example I am running an ABX Action during Pre Allocation of a new VM Build
Screen Shot of the Array Creation with Inputs:
- Here’s an example of PowerShell code that takes a YAML array string passed to an ABX Action, cleans it up, and converts it into a PowerShell array
- This is the most critical step in this blog post. Take the time to understand how the YAML string is transformed into a PowerShell array, as this enables you to leverage the array values for any automation tasks needed in your server build process.
- The PowerShell code processes the YAML string by replacing unnecessary characters, ensuring proper formatting, and then splitting the string on commas to create a PowerShell array. This transformation allows the data to be easily iterated and used within the ABX Action.
Screen Shot of the YAML Array Values:
- This example demonstrates how the YAML array format is passed to the ABX Action as a string. Understanding this format is essential for parsing and utilizing the array data effectively within your automation logic.
Screen Shot of the PowerShell Array Code Ouput:
- Example screen of PowerShell code output
Screen Shot of ABX successful run:
- Shows that the ABX Action was successfully run.
VCF Automation Design Template
Example Template Yaml Code:
- Code from the screen shots above.
|
|
VCF Automation Design Template
Example ABX Action Code:
- Code from the screen shots above.
- My example code simply outputs the values to demonstrate how to create the array and validate that the code works. Once you have this structure in place, you can extend the
foreach
section to automate any tasks you need.
|
|
Lessons learned:
- Using Array Inputs are a great way to use multiple values for processes needed to build new VMs.
- After you take the YAML array string and turn it into a PowerShell array, you can use the values to automate anything you can script.
I created a Google NotebookLM Podcast based on the content of this blog. While it may not be entirely accurate, is any podcast ever 100% perfect, even when real people are speaking? Take a moment to listen and share your thoughts with me!
vCROCS Deep Dive Podcast | VCF Automation | Input Arrays
In my blogs, I often emphasize that there are multiple methods to achieve the same objective. This article presents just one of the many ways you can tackle this task. I’ve shared what I believe to be an effective approach for this particular use case, but keep in mind that every organization and environment varies. There’s no definitive right or wrong way to accomplish the tasks discussed in this article.
Always test new setups and processes, like those discussed in this blog, in a lab environment before implementing them in a production environment.
If you found this blog article helpful and it assisted you, consider buying me a coffee to kickstart my day.