Cloud AssemblyIn the latest version of vRealize Automation (vRA), version 8, when you create a new blueprint for deploying a Virtual Machine, you probably noticed once you deploy the Virtual Machine it gets a standard machine name something like Cloud_Machine_1-mcmxxx-xxxxxxxxxxxx. But most customers use their own standard name convention. So, which options are there available for vRA customers to create custom names to be compliant with their standards? In this blogpost I’ll explain three options in vRA 8 (and vRA Cloud) to create custom names for VMs.

Using Infrastructure as Code

The first option is to rename your Machine objects on the design canvas in vRA Cloud Assembly. For example, when you drag & drop a Machine onto the canvas it gets a standard name like Cloud_Machine_1. Changing this in for example vmguru_machine results in a VM named something like vmguru_machine-mcmxxx-xxxxxxxxxxxx.

create custom names

create custom names

Another option is to add the name property to the YAML code. In my case I will use vmguru_vm. The VM will now be named vmguru_vm-mcmxxx-xxxxxxxxxxxx.

create custom names

create custom names

Be aware that the name property will overrule the object naming!

Using Custom Properties and the Custom Naming option

As you saw above, renaming the Machine object or using the name property still resulted in a VM name ending with mcmxxx-xxxxxxxxxxxx.

What if you don’t want this? Or you want to use vRA (custom) properties to build your VM name in a dynamic way?

This can be done with Custom Properties and the Custom Naming feature on a per vRA Project basis.

In vRA Cloud Assembly select the Infrastructure tab. Under Configure click on Projects. Open your Project and then select the Provisioning tab.

Under Custom Properties you can define properties with a name and value that will be added to every request in this Project. For example, a Country or Site code, a Cost Center etc. etc.

create custom names

Once you created your properties, go to Custom Naming. The template will define how your VM name will be generated. In the template you can use vRA Project-, Resource- and Endpoint Properties but also Username, User Email address and a Random number.

create custom names

create custom names

In my case my template looks like:

${project.name}-${resource.countryCode}-${resource.siteCode}-VM-${###}

This will generate the following VM name:

VMguru-NL-HLG-VM-xxx

Save your Project settings and deploy your blueprint.

create custom names

Be aware once you created a Project Custom Naming template, this will overrule naming a Machine object in the YAML code! Even the third option described below!

Using an Action script

The third option for renaming your VM uses a different approach.

In vRA 8 (and vRA Cloud) there’s a new extensibility feature called Action Based Extensibility. ABX in short. Instead of using vRealize Orchestrator workflows, ABX leverages Function as a Service to directly run an action script created in Python or NodeJS. For example, to tag a VM or do an API call to another system or Public Cloud Provider. Support for Powershell scripts will be added shortly.

To trigger the action, vRA uses Subscriptions to define conditions when the action should run based on a lifecycle event in the Event Broker.

Let me show you how to do this.

In vRA Cloud Assembly select the Extensibility tab. Under Library click on Actions. Click New Action.

Enter a Name for the action and select your Project.

create custom names

Click on Load Template and select Rename VM. Click Load.

create custom names

create custom names

In the left script pane, add [customProperties] in line 12 for the new_name inputs. With this we can create a custom property in a blueprint to be used for naming the VM.

create custom names

In the right properties pane, remove the input variables and select On prem as FaaS Provider.

create custom names

Save your Action.

Now we need to create a new blueprint which uses a Custom Property called newName. This property will be used in the Action to rename your VM. I’ll configure it as an input during request.

Go to Blueprints and create a new blueprint.

create custom names

Save and close your blueprint.

Go back to Extensibility. Click Subscriptions. Click New Subscription.

Enter a Name and select Compute Allocation as Event Topic.

create custom names

Toggle Filter events in topic and enter a condition. In my case I want the action to be related to the blueprint I just created. Here fore I need the blueprint ID. This ID can easily be found when going to the Blueprints tab and hover on the blueprint or selecting the blueprint. The hyperlink with the ID is than shown.

create custom names

Add the following condition:

event.data.blueprintId == ‘your-blueprint-id’

create custom names

Add your Rename VM action as Runnable item.

create custom names

Toggle Block execution of events in topic.

create custom names

Toggle the Subscription scope from Any project to your project. In my case the VMguru project.

create custom names

create custom names

Before going further, make sure that your Project isn’t configured with a Custom Naming template. Now request your blueprint.

Enter a custom VM name.

create custom names

Go back to the Extensibility tab. Under Activity click Action Runs. Here you can see your actions being run after being triggered by an event broker subscription.

create custom names

Click on the action run for more details. Select the Log tab.

create custom names

create custom names

Use Cloud-init to set the host name

In the previous paragraph we used an action to set the name of the VM. To make sure that the hostname in the Operation System equals this VM name, you can use Cloud-init to configure this. This off course requires a template with Cloud-init enabled!

Add the following Cloud-config to your blueprint:

create custom names

Now, when you deploy a VM with custom name, this name will also be used as hostname in the Operating System.

create custom names

create custom names

That’s it. vRA 8 makes it very easy to create custom names for your VMs using Infrastructure as Code, Custom Naming per Project or using ABX with Event Broker subscriptions.


Other articles in the series vRealize Automation: