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.
Next, create a file named repomount.sh using the vi editor with the following content and save it.
mount -t nfs $1:$2 /repo &>/repomount.log
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.
Now create the following build profile
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.
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.
echo "hello world" > /helloworld.log
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.
Let’s fill in the details to test this integration. Fill int he fields below with your NFS information and click submit.
If all worked as expected, login to your newly requested VM and check the root for the helloworld.log file.
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.
Now we need to login to our vCAC instance, type the following to connect
vra login userpass --user [email protected] --password MyPassword --server vcac-va.domain.com --tenant mytenant
Now let’s request that VM, mount a repo and run scripts in the guest. Type the following and press enter.
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.
Let’s just recap what we did and think about how powerful this is for your developers.
- We created a Linux blueprint with the vCAC guest agent installed and configured
- 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
- 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
- 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
- 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!!