Today I needed to assign some vCenter tags to some VMs I was deploying using vRealize Automation.
The scenario was that the customer did not want backup of VMs deployed by the vRA test environment, and in production they wanted a specific backup tier.
They are using Veeam backup, so the vRA test environment needed to have a NoBackup Tag, and production needed some other tag, depending on the type of server being deployed.
vRO does not provide very extensive support for these operations out of the box, but vRO 7.2 does come with some sample workflows.
To get started with vCenter tagging you need to configure a vAPI endpoint and a vAPI metamodel.
Setup vAPI Endpoint and metamodel
You can configure both the endpoint and metamodel by running the “Import vAPI metamodel” workflow.
Enter vCenter FQDN and service account credentials, if you want to use a specific account every time. Normally I would not want this, but since this is a vRA installation I need to.
If you get the following error, the reason is most likely that you did not/or should have set the domain name in front of your username.
Error:
List all tags/item2′, state: ‘failed’, business state: ‘null’, exception: ‘com.vmware.vapi.std.errors.unauthenticated => {data=<unset>, messages=[com.vmware.vapi.std.localizable_message => {args=[], default_message=This method requires authentication., id=vapi.method.authentication.required}]} (Workflow:List all tags / Scriptable task (item1)#6)
Then go ahead and get some additional packages for tagging.
Turns out that Oliver Leach has one that is quite useful. I looked through everything, and there was nothing suspicious at the time of writing, so I went ahead and imported the package. It can be downloaded directly off github.
https://github.com/oliverleach/virtualdevops/raw/master/com.virtualdevops.tags.package
I found it on Olivers own blog.
https://oliverleach.wordpress.com/2016/07/19/vrealize-orchestrator-7-vapi-vsphere-tags-workflow/
Additional functionality
I did miss a way to find a tag by its name, so I created a action for doing this.
I have forked Olivers project and added the Action. You can find it here: https://github.com/KnutssonDevelopment/vCenterTagging/blob/master/findTagByName.action
vRealize Automation Workflow
To define what tags I wanted on the deployed VMs, I created a vRA property called “vRA.Deployment.Tags” and assigned it to the blueprint. I can assign multiple tags, by separating them using semicolon. Ex: vRA.Deployment.Tags = “NoBackup;TestTag”
I then created a workflow that will use the payload from vRA, and add the tags. For this to work you will need to setup an event broker in vRA. Luckily Gary Coburn from VMware wrote an article about how to do this here: https://extendingclouds.com/enabling-the-event-broker/
Next you need to sort your workflow executions so that you can run the tagging once the machine has been deployed. This can be done in the event broker by only subscribing to the right events. You can see a great overview of the different event here: https://docs.google.com/spreadsheets/d/1l1dg6Elx3Z1Z8zPcKjyuUKbBiTP__yCktQ8XB7Sa6SY/edit also provided by Gary, or you can subscribe to all/most of them, and then sort them i vRO like I do. I will not be going into that in this article.
Afterwards import the package. I packed everything up into one file and placed it here: https://github.com/KnutssonDevelopment/vCenterTagging/blob/master/com.vGoodie-Bag.library.vapi.package
All you need to do it change the endpoint defined in the “setVcTags” workflow attributes.
Use everything at your own risk.
Hope you will enjoy it.
View Comments (5)
Hi Brian,
Thanks very much for this post, it's getting me on the right direction with tagging through vRA.
I've run across a snag I'm hoping you can help me with - I've got the setVcTags workflow being successfully called and it successfully "runs," but looks like it's failing at "findVcVmByName" and ends at that retry on the left in the schema. I'm looking at the script that tries to find the VM name, and it says this:
//Auto generated script, cannot be modified !
actionResult = System.getModule("dk.atea.library.vc.vm").findVcVmByName(vmName) ;
Is that correct? Is "dk.atea.library.vc.vm" the correct module? Is there another way I can call this?
Thanks!
Update: In looking at the variables from the last run, I see the following entries:
vmName > (it gives the correct VM name here)
errorCode > "Could not find VM (Dynamic Script Module name : findVcVmByName#7)"
So since it finds the correct vmName, not sure why it's not passing that on to vm/VC:VirtualMachine.
You can test the action in two ways, both require you to know you way around Orchestrator though.
First Way is to create a new test workflow and import the action into it, this will enable you to test the action to see if you get a VM object back from the action.
Secondly you could go to the action and copy the java script code from it, and then create a new test workflow, add a script object, and paste the java script code. You have to create inputs and outputs for the script to work, but this will enable you to debug the code.
This was a life saver for me.
Thank you
Hey Brian, is there any chance that you recreated this using vRO/vRA 8.X? I have been hitting my head against the wall trying to create something similar in 8. Especially since the payload function doesn't exist anymore. I would assume we would have to use inputProperties at some capacity.