Now that people are starting to build out vRealize Automation 7 in some environments, we find that we need to use some of the new features, or at least, we want to use the new features. One of the new features was the ability to export blueprints from vRA. This feature is not one that you will find in the vRA UI, oddly enough. (Ooooh…sounds like another potential blog post and project) VMware has given us a tool to use called vRealize CloudClient. vRealize CloudClient is a command-line tool that allows you to interface with the vRealize Automation API.
Many people who are use to writing scripts may find this tool extremely useful for some quick and dirty tasks. Hell, some may even find that it can be used for some more advanced and complex tasks. I am one of those people who was brought up in a Linux environment so I feel at home on the command-line. I digress, I needed to export all of my blueprints that I created…somewhere in the range of about 100 or so. I definitely didn’t want to recreate them one by one so in comes the ability to utilize the export blueprint functionality.
To get started you need to download the vRealize CloudClient from here and unzip it to a directory of your choosing. For me, on my Macbook, I just unzipped it to /Users/james/CloudClient
. You can also use the tool on Windows, just change the script file that you execute from the command-line, if you look in the directory you will see cloudclient.[bat|sh]
. You can use this tool interactively by just executing the cloudclient.[bat|sh] script. I won’t go into this as it is out of the scope of this article. When you go to export blueprints, you can only export one at a time.
That isn’t efficient for this use case, James!
I wasn’t about to sit here and run vra blueprint detail --id <bluePrintId>
for every single blueprint I had. Have no fear though, I wrote a script that you can reuse to export all of the blueprints. I wrote this script to work on my Mac so it should also work in Linux. I am sure with some clever fixing it can be made to run on Windows but I may let someone else tackle that. Anyway, on to the script. First we need to set some environment variables, so I have created a script to include in all of my scripts for this purpose. Let’s call it env.sh
. Here is the script:
As you can see above, I have used a plaintext password. There are other methods that involve using keys but for the sake of simplicity I chose to use a plaintext password passed through here. The above script will set the environment variables required to make a connection to your vRA server from the CloudClient.
Now we need to create the script that will actually make the magic happen. Let us create another script and call it exportBlueprints.sh
. Here is the script that I created:
In line 12, we are calling our environment variable script to set the variables we want for connection to vRA through the CloudClient shell.
In line 15, we call the CloudClient script with the command of vra blueprint list
with some options to generate a list of the blueprints in your tenant.
In line 18, we are stripping off the second returned value for each line since the command on line 15 returns id, name and we only want the id for our script.
In lines 21-23, we take the massaged output and run through a loop for each one until complete, exporting the blueprint to a YAML file for use to import.
Just kick off the script from the command-line and watch it export each one of your blueprints. The process still takes a while because it seems like the CloudClient checks the active session each time it runs because of the way we call the script. (If someone else knows different or another way to speed this up then please let me know!)
I hope that this saves you some time. This can also open up the doors to more exciting ways to manage or create blueprints. Let me know in the comments what use cases you see coming from this!
Updates#
- Added logout at the end of the script (03/18/2016)