You already have a large vSphere environment and your developers are quickly eating up space on their Laptops or worse, they are going out to a Public cloud on their corporate card. Why not enable them to use their favorite tools on vSphere? This post is not about using Vagrant or Vagrant on vSphere. This post is primarily focused on showcasing the power of VMware Photon as a Container host for agile application development. With that said most of this post should also work with other flavors or Linux that Vagrant supports but no guarantees there.
Download and install the latest version of Vagrant. I am using Vagrant on CentOS 6.6 x64 . This will become my developer machine.
Next, we need to install and configure the Vagrant vSphere Provider by typing vagrant plugin install vagrant-vsphere and press enter see link for more info on this plugin
vagrant plugin install vagrant-vsphere
You will also need a Photon template available in vCenter before we continue on the Developer Machine. See the following guide to create your Photon Template in vSphere.
I set my password to vagrant
Now type visudo then press i and scroll down and add the following line then press esc key then hold shift and press ZZ to save it
vagrant ALL=(ALL) NOPASSWD:ALL
mkdir -p /home/vagrant/.ssh
Now get the keys using the following
Note: It is one single line, make sure not to have a hard return when you copy and paste or this won’t work
wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
Now lets reset permission on the keys, copy and paste each line below the screenshot and press enter.
Be sure to enter each line and press enter separately
chmod 0700 /home/vagrant/.ssh
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh
Back on the CentOS instance where we installed Vagrant earlier we need to create a dummy box.
Find where the example box is by typing the following
find / -name example_box
tar cvzf dummy.box ./metadata.json
Next we will create a new folder under /root for storing the box file we created and other vagrant configuration files
mkdir -p ~/vagrant-vms/example_box
mv dummy.box ~/vagrant-vms/example_box
Click i to change to insert mode and past the following into the file, then pres ESC key and then Hold Shift and hit ZZ to save it
Make sure to change the settings for your vSphere environment
Vagrant.configure("2") do |config| config.vm.box = 'vsphere' config.vm.box_url = './example_box/dummy.box' config.vm.provider :vsphere do |vsphere| # The host we're going to connect to vsphere.host = 'vcsa-01a.corp.local' # The host for the new VM vsphere.compute_resource_name = 'Cluster Site A' # The resource pool for the new VM vsphere.resource_pool_name = 'VagrantVMs' # The template we're going to clone vsphere.template_name = 'Photon' # The name of the new machine vsphere.name = 'Photon-Vagrant' # vSphere login vsphere.user = 'email@example.com' # vSphere password vsphere.password = 'VMware1!' # If you don't have SSL configured correctly, set this to 'true' vsphere.insecure = true end end
Install the Vagrant Photon Guest Plugin by typing vagrant plugin install vagrant-guests-photon and press enter
vagrant plugin install vagrant-guests-photon
Now type vagrant up –provider=vsphere and press enter
Note you will get an rsync error, just ignore this.
sudo docker run -d -p 80:80 vmwarecna/nginx