How to call vCAC (vRA) from command line to request VM’s and run scripts in the guest

So you want to make your developers happy but you are a vSphere admin and you already have enough on your plate? I am going to make it super easy for you to give your developers what they want (a command line to script their infrastructure request) and what you want, (an easy to use and administer UI). So let’s get started. A couple of things you will need in place:

  • vCAC 6.0 or 6.1 installed and configured
  • Linux Guest agent template see my guide here
  • vRealize Cloud client 3.0, download from here.
  • An NFS server with a script directory available for your developers to mount to their Linux VM’s
  • A quite place to work for a few hours where you will not be interrupted.

Power on your Linux guest agent template and login as root or sudo to root and create directory on the root file system named repo. This is where you will mount your NFS share to.

media_1414087558649.png

Next, create a file named repomount.sh using the vi editor with the following content and save it.

media_1414087673570.png
mount -t nfs $1:$2 /repo &>/repomount.log

Make the repomount.sh executable by typing the following then pressing enter

chmodrepomount
chmod u+x repomount.sh

Now shutdown your template. If you are using Linked clones you will also need to take a new snapshot and then run an inventory scan in vCAC and update the blueprint to point to the new snapshot

Now let’s create the build profile for this blueprint to use. Login to vCAC and navigate to the Infrastructure tab, then Blueprints, then Build Profiles and click to create a new build profile.

media_1414085844034.jpg

Now create the following build profile

media_1414086727779.jpg
repo.path
repo.server
VirtualMachine.Admin.UseGuestAgent true
VirtualMachine.Customize.WaitComplete true
VirtualMachine.Software0.Name repomount.sh
VirtualMachine.Software0.ScriptPath /repomount.sh {repo.server} {repo.path}
VirtualMachine.Software1.Name
VirtualMachine.Software1.ScriptPath
VMware.VirtualCenter.OperatingSystem rhel6_64Guest

Now navigate to your Linux guest agent blueprint and attach this build profile to it and save it.

media_1414087992924.jpg

What this integration will actually do: It will call the repomount.sh script to mount the NFS share on the server you specify and to the directory you speicfy at request time. It will mount that NFS share to the /repo directory in the guest. Next it will execute the script you specify that is in the NFS share. The script will always need to run relevant to /repo.

Almost there, now we will need to create a test script on our repo server. I have setup a Linux server and I exported a directory named scripts as a read only NFS share. In that directory create a file named helloworld.sh with the following and save it.

media_1414089188439.png

echo "hello world" > /helloworld.log

Now make the file executable by typing chmod u+x helloworld.sh and press enter

chmodhelloworld

Before we use the command line let’s do a smoke test from the vCAC UI, open the catalog and fire off a new request. Your request form should look like this.

media_1414089522349.png

Let’s fill in the details to test this integration. Fill int he fields below with your NFS information and click submit.

properties

If all worked as expected, login to your newly requested VM and check the root for the helloworld.log file.

media_1414090483103.png

Ok enough using the GUI, we know developers aint got time for that! Launch cloud client and accept the EULA. I am using the Windows version, type cloudclient.bat You should see the following screen.

media_1414090717228.png

Now we need to login to our vCAC instance, type the following to connect

media_1414090801250.png
vra login userpass --user user@domain.com --password MyPassword --server vcac-va.domain.com --tenant mytenant

Type the following to verify connectivity

media_1414090878819.png
vra catalog list

Now let’s request that VM, mount a repo and run scripts in the guest. Type the following and press enter.

media_1414093875856.png
vra catalog request submit --groupid "Rainpole Developers" --id CentOS6 --reason Because --properties repo.path=/scripts,repo.server=192.168.110.134,VirtualMachine.Software1.Name=helloworld.sh,VirtualMachine.Software1.ScriptPath=/repo/helloworld.sh,provider-VirtualMachine.CPU.Count=1,provider-VirtualMachine.Memory.Size=512

In the vCAC portal you should see a new request in progress. But let’s take a look from the command line. Type vra provisioned item list and if your machine is ready you should see the following.

media_1414094007914.png

Open an SSH session to your new machine and check for the helloworld.log file

media_1414094098919.jpg

Let’s just recap what we did and think about how powerful this is for your developers.

  1. We created a Linux blueprint with the vCAC guest agent installed and configured.
  2. We added a repomount script to the Linux template that will mount a repo directory where a developer could call whatever scripts they want in the guest.
  3. We created a custom build profile that will take user input at request time so requester can specify the repomount server they want, the NFS share and the script they want to run in the guest.
  4. We requested a new VM, specified the repo server and NFS share and the script we want to execute in guest from a command line
  5. Verified the script ran in the guest

So where do we go from here! Now your developers are enabled to write scripts that can do a number of things like install software, configure the server, pull artifacts from a repository, install configuration management solutions like Chef, Puppet, Salt or Even docker. All of this completely scripted and automated. The future is now!!

Remember, sharing is caring ->Tweet about this on Twitter
Twitter
Share on Facebook
Facebook
0Share on LinkedIn
Linkedin
Email this to someone
email

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.