posted

2 Comments

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 How to create a vCAC 6 Linux Guest Agent Template
  • 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.

Ok, so let’s get going!

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

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

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

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

media_1414087763776
chmod 777 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

Now create the following build profile

media_1414086727779
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

 

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
echo "hello world" > /helloworld.log

Now make the file executable by typing chmod 777 helloworld.sh and press enter

media_1414089264291

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

media_1414089522349

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

Ok enough using the GUI, we know developers don’t have time for that! Launch cloud client and accept the EULA. I am using the Windows version but it is written in Java so it works on Linux too, type cloudclient.bat You should see the following screen.

media_1414090717228

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

media_1414090801250

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

Type the following to verify connectivity

media_1414090878819
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
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

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

media_1414094098919

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!!