Indentation in YAML
Unlike many computer programming languages, YAML is sensitive to indentation:
- In YAML, indentation denotes nested blocks.
- All items in a nested block must be indented equally.
- Use spaces to indent. Tabs are not allowed.
- The YAML editor in VMware Aria Automation draws vertical lines to show where spaces are used to indent code.
You can use any number of spaces to indent a section. Subsections that are at the same level must have the same number of spaces.
If you have the same type of items in the code that are indented with a different number of spaces, the YAML editor displays a syntax error. In the example, all items under properties (image, customizationSpec, and networks) must be indented with the same number of spaces.
Comments in YAML
As VMware Aria Automation templates become more complicated, include comments for documentation:
- A # symbol anywhere in the YAML code makes everything following the # to be treated as a comment.
- A # symbol at the beginning of a line makes the entire line a comment.
- A # symbol at the end of a line adds a comment about that specific line.
- A # symbol that is enclosed by single or double quotation marks is not treated as a comment.
If you place a # symbol in single or double quotation marks, it is not treated as a comment. For example, in image: ‘VMW-CentOS#’, the YAML code looks for an image named VMW-CentOS#.
To use this comment correctly, change the line to image:’VMW-CentOS’ #<write_comment_here>.
Key-Value Pairs in YAML
YAML stores data in a map that contains keys and values:
- The format is <KEY>: <VALUE>.
- The value can be enclosed in single quotes.
- When using several key-value pairs, their order in the YAML code does not matter.
YAML stores data in a map of key-value pairs.
Each pair must always have a colon (:) between the key and the value.
The order of the key-value pair does not matter. You can have flavor: <flavor_name> followed by image: <image_name> or image: <image_name> followed by flavor: <flavor_name>.
The YAML editor guides you about the possible key-value pairs at a specific point in the YAML code.
Examples of key-value pairs:
- image: <image-name>
- flavor: <flavor_name>
- type: <any type, depending on where you are in the code>
Lists in YAML
Lists are used to store a collection of values in order:
- Lists begin with a key followed by a colon (:).
- Each list item starts with a hyphen (-).
- All list items in a list must be indented equally.
Lists are useful when you define variables or inputs.
Variables in YAML
Variables in YAML start with the $ character:
- Variables can be used to reference other components in the YAML code.
- Variables can also be used with user inputs.
Variables can also be used with user inputs. When referenced, these variable names start with the input. text.
The first part of the variable name (for example, resource.) describes the part of the YAML code that the variable comes from.
If you connect two objects in the design canvas, a variable that points to the connected object is added automatically in the YAML code to the object that is connected to it. These variables always end with the .id text.
User Inputs in YAML
User inputs enable the user to select options from a list of choices:
- The list is defined in YAML.
- Assign the variable to any name that you like.
- Define the list as a type of string and delineate the list items under enum.
- Use the variable anywhere in the YAML code:
- Begin the variable with ‘${input.
- End with the variable name and a right brace, for example, ‘${input.SelectFlavor}’.
When you define an input variable, it appears in the inputs section (plural). When you reference the variable, it is singular ${input.<variable_name>}.
Formatting Text in a VMware Aria Automation Template
To create a user-friendly input on your choice list, you might want to concatenate the text or change the case.
In the example, a user input was created that enables the user to choose between multiple cloud platforms. But these choices might not match the capability tags that were defined. YAML code addresses this issue.
The YAML takes the input, adds the word cloud: before it, and switches all the input to lowercase.
The concatenated text gives the exact name of a capability tag that you previously created in VMware Aria Automation.
The YAML code includes ‘${”cloud:”””. The part of the code has a single quote, ${cloud, a colon (:), two double quotes, and one single quote. The colon (:) is a special character in YAML. To use a colon in a string, two double quotes must follow the colon. The :”” code allows the colon (:) to be used in a string. The two double quotes are like an escape character.
As an alternative to this approach, using oneOf instead of enum provides an easier solution. In the drop-down menu defined by an enum, each entry in the list is a single value such as AWS. Because that value does not match the hypothetical capability tags, the earlier example converted the value that the user selects to precisely match a capability tag. When defining a drop-down menu using oneOf, each entry in the list is a pair. Each pair consists of a value that appears in the drop-down menu and a value that is returned to VMware Aria Automation. For example:
oneOf:
- title: AWS
const: 'cloud:aws'
- title: Azure
const: 'cloud:azure'
- title: GCP
const: 'cloud:gcp'
- title: vSphere
const: 'cloud:vsphere'Using Escape Characters
Configuration files often require the following special characters:
- The standard escape character in YAML is the backslash (\).
- You can escape a single quote (‘) by enclosing it in a pair of double quotes.
- You can escape a colon (:) by following it with two double quotes.
A single colon in YAML is a special character and requires a special escape character. To use a colon in a string, two double quotation marks must follow the colon. The :”” code allows the colon (:) to be used in a string. The two double quotation marks act as an escape character.
Evaluating Expressions in the VMware Aria Automation Template
Set values based on the evaluation of an expression.
In the example, YAML evaluates the value of the SelectCloud input variable.
The == expression tests the value of the variable to see if it equals what follows. In the screenshot, if SelectCloud is equal to <some_value>, then <perform_some_action>. The == expression is the syntax equivalent of “is equal to.”
The ? expression is the equivalent to a Then clause in an If-Then-Else expression.
If SelectCloud is equal to vSphere, the folderName property is set to Production_VMs.
If SelectCloud is not equal to vSphere, the folderName property is set to a blank.
Several other conditional expressions are available:
- Equality operators are == (equal to) and != (not equal to).
- Logical operators are && (and), || (or), and ! (not).
- Relational operators are < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to).
Conditional expressions always use the following pattern: conditional-expression ? true-answer : false-answer
For more information about the VMware Aria Automation Assembler expressions syntax, see at https://techdocs.broadcom.com/us/en/vmware-cis/aria/aria-automation/8-17/assembler-on-prem-using-and-managing-master-map-8-17/maphead-designing-your-deployments/expressions-general.html
Conditional Deployment in the VMware Aria Automation Template
Deploy an object only if specific values are set.
In the example, the user is prompted whether to perform a clustered deployment or to deploy a single machine. The user’s response is stored in the DeploymentMode input variable.
If DeploymentMode is set to Cluster, three machines and one load balancer are deployed.
If DeploymentMode is set to Single, one machine and zero load balancers are deployed.
Discover more from Cloud Blogger
Subscribe to get the latest posts sent to your email.










