Integrating vRA with Pivotal Container Service (PKS)
Posted: October 17, 2018 Filed under: kubernetes, Pivotal Container Service, vRealize Automation | Tags: pks, vRA 2 CommentsOverview
This guide will show you how to integrate vRA with PKS.
Adding or Updating a vRealize Automation machine’s custom property
Posted: April 17, 2018 Filed under: vRealize Automation | Tags: vRA Leave a commentRecently I’ve had a few people ask how to add or update a custom property on an already deployed vRealize Automation (vRA) machine. Several people unregistered the machine using CloudClient, updated a blueprint with the new custom property and then bulk imported the machine back into vRA. It’s actually much easier than that.
Integrating vRealize Automation 7.3 with Puppet Enterprise
Posted: July 31, 2017 Filed under: vRealize Automation | Tags: Puppet, vRA, vRO Leave a commentStarting with vRealize Automation 7.3 (vRA) there is native integration with Puppet. This means that there are now Puppet object within the vRA interface that you can drag and drop onto your blueprints as well as select Puppet constructs such as roles from dynamic drop down lists while building and deploying vRA blueprints. You can read the annoucement from Puppet here. Puppet has also provided some starter content to make getting up and running quick.
vRealize Automation Softare Provisioning with Ansible, Powershell, Jenkins and GitLab
Posted: June 28, 2017 Filed under: vRealize Automation | Tags: ansible, jenkins, Powershell, vRA Leave a commentI’m going to show you how you can use vRealize Automation (vRA), Ansible, Powershell, GitLab and Jenkins together to test software deployments. There are many ways to accomplish what I’m going to demonstrate, but I’m going the simple route in most cases as it will be easier to cover in blog form. Throughout the post I’ll point out other options you may want to explore.
The end result is that when we push new code to our repository it will kick off a Jenkins job that will provision a vRA machine which will proceed to install software based off our updated code.
Troubleshooting vRealize Automation Provisioning
Posted: May 1, 2017 Filed under: vRealize Automation | Tags: vRA Leave a commentIf you’ve worked with vRealize Automation (vRA) for any amount of time you’ve most likely experienced a provision that has either failed or gotten stuck in progress. I’m going to show how you can begin troubleshooting these scenarios.
Using Powershell to work with vRealize Automation work items
Posted: January 31, 2017 Filed under: vRealize Automation | Tags: Powershell, vRA Leave a commentI’m going to show how to use Powershell to access a vRealize Automation (vRA) work item and use the work item data to add the machine requestor to the local admins group of the provisioned machine.
This script is for demonstration purposes only and not intended for production use. Please do not call VMware GSS with questions relating to this post as they will not be able to assist.
Provisoning vRealize Automation Catalog Items with Powershell and REST
Posted: January 25, 2017 Filed under: vRealize Automation | Tags: Powershell, vRA 2 CommentsI’ve dabbled with Powershell in the past but never considered it one of my go to languages since it was only available on Windows. This limited my usage of Powershell to primarily working with VMware’s PowerCLI, but now that Powershell has been ported to Linux and OSX I’ve decided to put more effort into learning it. At work I’m working with vRealize Automation (vRA) so I thought I’d try to provision some vRA catalog items via Powershell and REST. Compared to other languages I’ve used, Powershell makes working wtih RESTful APIs very easy. Let’s get started.
This post is designed so you can follow along line by line. You can find a functionalized version on Github.
You can follow along by opening up a Powershell window. Let’s set up some variables:
$vraServer = ‘vra72.vmware.local’
$catalogItem = ‘CentOS 7 Base’
$username = ‘cloudadmin’
$password = ‘VMware1!’
$tenant = ‘vsphere.local’
Getting a login token
The first thing we need to do is get a login token from vRA. You can find out more about this in the vRA API Documentation. You can see an example request in curl here. We can get a login token by making a request to the following URL:
As described in the above links, we must be a POST request and the body of the request must be our username, password and tenant in JSON format. Powershell makes this really easy. Let’s start by defining a hash table with the required values:
$properties = @{‘username’ = $username; ‘password’ = $password; ‘tenant’ = $tenant}
If we view the contents of our $properties variable, we will see the following:
Now let’s convert this into a Powershell object:
$bodyObject = New-Object –TypeName PSObject –Property $properties
Viewing the contents of $bodyObject gives us:
We still need to convert this to JSON as this is what the request for a token requires. This can easily be done like so:
$body = $bodyObject | ConvertTo-Json
The $body variable looks like this:
If you’ve worked with JSON in the past this should look familiar.
Now we are going to request another hash table containing our headers:
$headers = @{“Content-Type” = “application/json”; “Accept” = “application/json”}
We are now ready to request our login token:
$request = Invoke-WebRequest $url -Method POST -Headers $headers -Body $body
Here you can see we used Poweshell’s Invoke-WebRequest
commandlet. We specified the method as POST
along with our headers and body. The $request variable looks like this:
If you look at Content
you’ll see that it contains our token along with other information such as the expiration date. The value of Content is a Powershell String, but we want it in JSON format so we can parse out the id. We can do this by running:
$content = $request.content | convertFrom-json
$content contains:
To get the id, we just need to grab the id field:
$bearerToken = $content.id
The $bearerToken variable will look something like this:
Requesting a catalog item
To request a catalog item we need to perform the following:
- Make a GET request on the entitled catalog items
- Make a GET request to get the view of our catalog item
- Get a the request template for our catalog item
- Make a POST request for our catalog item
I’m not going to go into as much detail as in the Getting a login token
section as it’s the same pattern over and over.
In the following block of code we specify the URL that contains our entitled catalog items, define $headers again but this time we specify an Authorization header and use our bearer token, make our request and convert the returned content into JSON:
$url = “https://$($vraServer)/catalog-service/api/consumer/entitledCatalogItems/”
$headers = @{“Content-Type” = “application/json”; “Accept” = “application/json”; “Authorization” = “Bearer ${bearerToken}”}
$request = Invoke-WebRequest $url -Method GET -Headers $headers
$content = $request.Content | ConvertFrom-Json
If we look at the content field of $contentJson, we see we have various catalog items:
How do we know what’s in each of these? Let’s grab the first one item and see what type of Poweshell object it is:
So we can see that the BaseType
is an object. This means we can use the Get-Member
commandlet to get all the objects members or fields:
The catalogItem
field looks promising. Let’s check it out:
OK, so we know we look at $contentJson.content
we get a list of catalog items and we can look at the catalogItem
field to get details about each one. To find which item we are looking for $catalogItem
, we can do the following:
$consumerEntitledCatalogItem = $content.content | where { $_.catalogItem.name -eq $catalogItem }
Let’s verify that we have the correct catalog item:
In the next block we will get the catalog item’s id since that’s what we will append to the catalog item view URL, make our request and convert the results to a Powershell object:
$consumerEntitledCatalogItemId = $consumerEntitledCatalogItem.catalogItem.id
$url = “https://$($vraServer)/catalog-service/api/consumer/entitledCatalogItemViews/$($consumerEntitledCatalogItemId)”
$request = Invoke-WebRequest $url -Method GET -Headers $headers
$content = $request.Content | ConvertFrom-Json
If we look at at the links field of $content, we will see:
We need the href that ends in template
and we can get it like this:
$requestTemplateURL = $content.links | ? { $_.rel -eq ‘GET: Request Template’ }
Let’s go ahead and get the POST URL while we’re at it:
$requestPOSTURL = $content.links | ? { $_.rel -eq ‘POST: Submit Request’ }
Now we can make a request to $requestTemplateURL. This will allow us to access a “template” of the request data. Once we have this we can either use the same data to make a request or modify somehow like changing the number of CPUs we want:
$request = Invoke-WebRequest $requestTemplateURL.href -Method GET -Headers $headers
Now we have everything we need to make the catalog item request:
$request = Invoke-WebRequest $requestPOSTURL.href -Method POST -Headers $headers -body $request.content
If the request was successful, you should see a status code of 201 and the request should be In Progress
in vRA:
Here are all of the steps:
$vraServer = ‘vra72.vmware.local’
$catalogItem = ‘CentOS 7 Base’
$username = ‘cloudadmin’
$password = ‘VMware1!’
$tenant = ‘vsphere.local’$url = “https://$($vraServer)/identity/api/tokens”
$properties = @{‘username’ = $username; ‘password’ = $password; ‘tenant’ = $tenant}
$bodyObject = New-Object –TypeName PSObject –Property $properties
$body = $bodyObject | ConvertTo-Json
$headers = @{“Content-Type” = “application/json”; “Accept” = “application/json”}
$request = Invoke-WebRequest $url -Method POST -Headers $headers -Body $body
$content = $request.content | convertFrom-json
$bearerToken = $content.id$url = “https://$($vraServer)/catalog-service/api/consumer/entitledCatalogItems/”
$headers = @{“Content-Type” = “application/json”; “Accept” = “application/json”; “Authorization” = “Bearer ${bearerToken}”}
$request = Invoke-WebRequest $url -Method GET -Headers $headers
$content = $request.Content | ConvertFrom-Json
$consumerEntitledCatalogItem = $content.content | ? { $_.catalogItem.name -eq $catalogItem }
$consumerEntitledCatalogItemId = $consumerEntitledCatalogItem.catalogItem.id
$url = “https://$($vraServer)/catalog-service/api/consumer/entitledCatalogItemViews/$($consumerEntitledCatalogItemId)”
$request = Invoke-WebRequest $url -Method GET -Headers $headers
$content = $request.Content | ConvertFrom-Json
$requestTemplateURL = $content.links | ? { $_.rel -eq ‘GET: Request Template’ }
$requestPOSTURL = $content.links | ? { $_.rel -eq ‘POST: Submit Request’ }
$request = Invoke-WebRequest $requestTemplateURL.href -Method GET -Headers $headers
$request = Invoke-WebRequest $requestPOSTURL.href -Method POST -Headers $headers -body $request.content