In our previous installment, we covered the basics of using Vagrant with VMware Integrated OpenStack. In today’s article, we will take a look at a multi-instance deployment from a single Vagrantfile. Today’s sample Vagrantfile looks almost identical to our previous example with a few changes, highlighted in bold, that we discuss below.
Let’s go back to the same directory where you created your Vagrantfile from our previous walkthrough. Make sure that your old Vagrant instance is deleted using the following command:
vagrant destroy -f
Now backup your original Vagrantfile if you would like to preserve it. Then, replace your Vagrantfile content with the code that follows.
puts "\nHave you sourced your OpenStack creds today???\n"
nodes = ['master','node1']
Vagrant.configure("2") do |config|
config.vm.box = "openstack"
config.ssh.private_key_path = "~/.ssh/id_rsa"
nodes.each do |server|
config.vm.define "#{server}" do |box|
config.vm.provider :openstack do |os|
os.endpoint = "#{ENV['OS_AUTH_URL']}/tokens" # e.g. "#{ENV['OS_AUTH_URL']}/tokens"
os.username = "#{ENV['OS_USERNAME']}" # e.g. "#{ENV['OS_USERNAME']}"
os.tenant_name = "#{ENV['OS_TENANT_NAME']}"
os.api_key = "#{ENV['OS_PASSWORD']}" # e.g. "#{ENV['OS_PASSWORD']}"
os.flavor = /m1.small/ # Regex or String
os.image = /ubuntu/ # Regex or String
os.keypair_name = "demo-keypair" # as stored in Nova
os.ssh_username = "ubuntu" # login for the VM
os.networks = ["demo-network"]
os.floating_ip = :auto
os.floating_ip_pool = "EXTNET"
end
end
end
end
Vagrant is written in Ruby, and this allows us to use Ruby constructs to control how instances are deployed. For example, we use a Ruby list of strings (nodes = [‘master’,’node1′]) near the top of the file to declare the names of multiple servers that we want Vagrant to create for us in the OpenStack cloud.
We leverage a Ruby iterator (each), which will run the code that follows it for each element of the list. We have two entries in the node list. So, the Vagrant instructions will be run two times. If you would like to create more than two nodes, you are free to add multiple names to that list up to the limit of instances specified by your OpenStack project’s quota.
When Vagrant is done provisioning your environment, you will see messages on the commandline similar to the following:
==> node1: The server is ready!
==> node1: Configuring and enabling network interfaces...
==> master: The server is ready!
==> master: Configuring and enabling network interfaces...
==> node1: Rsyncing folder: /Users/trobertsjr/Development/vagrant-on-openstack/ => /vagrant
==> master: Rsyncing folder: /Users/trobertsjr/Development/vagrant-on-openstack/ => /vagrant
You can then use the following command to verify that your OpenStack instances were created successfully and are available for use:
vagrant status
This command’s output should show an active state for your instances:
Current machine states:
master active (openstack)
node1 active (openstack)
This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
The nova CLI will also show your instances being active and available:
(openstack)vagrant-on-openstack $ nova list
+--------------------------------------+--------+--------+------------+-------------+-----------------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+--------+--------+------------+-------------+-----------------------------------------+
| 38702893-4b33-4f77-ba9a-07c99ab16318 | master | ACTIVE | - | Running | demo-network=192.168.0.41, 10.115.96.32 |
| 45f9d279-d6fb-48b7-a191-985eed9452fc | node1 | ACTIVE | - | Running | demo-network=192.168.0.40, 10.115.96.31 |
+--------------------------------------+--------+--------+------------+-------------+-----------------------------------------+
Finally, you can ssh into the instances using Vagrant as you did with our previous post, but you will need to specify the name of the instance you are connecting to this time.
vagrant ssh master
or
vagrant ssh node1
Try Vagrant with VMware Integrated OpenStack today, and let us know how it worked out for you!
You can learn more about VMware Integrated OpenStack on the VMware Product Walkthrough site and on the VMware Integrated OpenStack product page.