vRealize Orchestrator 6.0 and executing a workflow with parameters via the REST API from Powershell using Invoke-RestMethod and a json payload
Some Powershell functions that can be used to invoke a REST API call, with a json payload, against a vRO workflow with parameters.
As part of a fairly complex piece of server automation work being completed, there was a requirement to
be able to call a workflow that I’d created within the vRO. The particular workflow in question was one that used
the vRO Puppet plugin to classify a Linux based node, CentOS in this example, and remediate.
This workflow is to be called after the VM has been built to spec and has been registered within DNS.
(Further article to follow on how I register DNS records via Powershell)
The majority of the server automation is driven from a Powershell module that gets called via the vRA (vRealize Automation Center)
from an Advanced Services blueprint.
To execute a vRO workflow via the REST API, with parameters, from a Powershell function.
vRO workflow has a number of parameters that have to be passed to it to execute correctly.
Infrastructure setup in this example
vRealize Orchestrator is embedded within the vRealize Automation appliance.
The Powershell module (that contains the functions) exists on the registered Powershell host.
The Powershell host used to initiate Powershell scripts is the vRealize IaaS server (added as a Powershell host).
The Powershell version used here is v3.0 running on Windows 2012 R2 Server.
The functions assume that a vCenter connection has already been established with the appropriate rights.
The following functions exist within a Powershell module files (.psm1) to be called as and when.
The functions do not have appropriate error handling.
The vRO workflow
The vRO workflow in this example is expecting the following parameters;
className = The classname you want to inject into the <nodename.pp> file
masterName = The Puppet master server
environment = The environment that the Puppet master is going to use. i.e., dev, prod etc
vmMoRefID = The VM Managed Object Reference ID, for example 'vm-246870'
The Powershell Code
The LogWrite function call you will see below is a function I use to create my log files. I haven’t supplied that function here, so
you can just comment it out.
Function ExecutevROWorkflow - executes a vRO workflow
Function GenerateJsonForPuppetWorkflow - creates a correctly formatted json string to be used with the REST API call in the above function
Function GetMoRefFromVMName - returns the MoRefID of a virtual machine from a currently established vCenter connection
This is used to identify the VC:Virtualmachine object of the VM as a required input to the vRO workflow that runs later.
If you have any questions, comments or praise/criticsm please drop it into the comments thread below.