Vagrant has become very popular for provisioning virtual machines for development. Usually it’s used in combination with VirtualBox on a local machine. But Vagrant supports multiple other visualization providers, in fact one can build a custom provider as needed. If the local machine is not sufficient for the needs of development moving to the cloud seems like a reasonable thing to do using AWS, Rackspace, or OpenStack.
Getting Started
To get started with Vagrant OpenStack you need to install the plugin first.
Vagrant expects a box to be provisioned which is in case of a cloud not really present. Therefor a dummy box is installed an later referenced in the Vagrantfile.
You can now configure OpenStack in you Vagrantfile accordingly. There are a few basic and needed settings like the API, user, and password. Some optional parameters help in fine tuning the setup.
require 'vagrant-openstack-plugin'
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
# Make sure the private key from the key pair is provided
config.ssh.private_key_path = "~/.ssh/openstack_rsa"
config.vm.provider :openstack do |os|
os.username = "hkropp" # e.g. "#{ENV['OS_USERNAME']}"
os.api_key = "passw" # e.g. "#{ENV['OS_PASSWORD']}"
os.flavor = /m3.medium/ # Regex or String
os.image = /centos-6.4/ # Regex or String
os.endpoint = "http://172.24.74.252:5000" # e.g. "#{ENV['OS_AUTH_URL']}/tokens"
os.keypair_name = "openstack_rsa" # as stored in Nova
os.ssh_username = "root" # login for the VM
end
end
Optional parameters:
os.metadata = {"key" => "value"} # optional
os.user_data = "#cloud-confignmanage_etc_hosts: True" # optional
os.network = "YOUR NETWORK_NAME" # optional
os.networks = [ "internal", "external" ] # optional, overrides os.network
os.address_id = "YOUR ADDRESS ID" # optional (`network` above has higher precedence)
os.scheduler_hints = {
:cell => 'australia'
} # optional
os.availability_zone = "az0001" # optional
os.security_groups = ['ssh', 'http'] # optional
os.tenant = "YOUR TENANT_NAME" # optional
os.floating_ip = "33.33.33.33" # optional (The floating IP to assign for this instance)
os.orchestration_stack_name = 'stack01' # optional
os.orchestration_cfn_template_file = '/tmp/cfn_heat_template.json' # optional
os.orchestration_cfn_template_parameters = { # optional
'NetworkName' => 'net_01'
}
List of settings:
api_key– The API key for accessing OpenStack.flavor– The server flavor to boot. This can be a string matching the exact ID or name of the server, or this can be a regular expression to partially match some server flavor.image– The server image to boot. This can be a string matching the exact ID or name of the image, or this can be a regular expression to partially match some image.endpoint– The keystone authentication URL of your OpenStack installation.server_name– The name of the server within the OpenStack Cloud. This defaults to the name of the Vagrant machine (viaconfig.vm.define), but can be overridden with this.username– The username with which to access OpenStack.keypair_name– The name of the keypair to access the machine.ssh_username– The username to access the machine. This can also be configured using the standard config.ssh.username configuration value.metadata– A set of key pair values that will be passed to the instance for configuration.network– A name or id that will be used to fetch network configuration data when configuring the instance. NOTE: This is not compliant with the vagrant network configurations.networks– An array of names or ids to create a server with multiple network interfaces. This overrides thenetworksetting.address_id– A specific address identifier to use when connecting to the instance.networkhas higher precedence. If set to :floating_ip, then the floating IP address will be used.scheduler_hints– Pass hints to the open stack scheduler, see--hintflag in OpenStack filters docavailability_zone– Specify the availability zone in which the instance must be created.security_groups– List of security groups to be applied to the machine.tenant– Tenant name. You only need to specify this if your OpenStack user has access to multiple tenants.region– Region Name. Specify the region you want the instance to be launched in for multi-region environments.proxy– HTTP proxy. When behind a firewall override this value for API access.ssl_verify_peer– sets the ssl_verify_peer on the underlying excon connection – useful for self signed certs etc.floating_ip– Floating ip. The floating IP to assign for this instance. If set to :auto, then this assigns any available floating IP to the instance.orchestration_stack_name– Name for orchestration stack. Mandatory parameter when creating new stack. One of parameters for template should be set with this parameter.orchestration_stack_destroy– If stack created by vagrant should be deleted when destroy action is invoked. Default value isfalse.orchestration_cfn_template– AWS CloudFormation Template specified as a string.orchestration_cfn_template_file– AWS CloudFormation Template file path accessible for vagrant.orchestration_cfn_template_url– AWS CloudFormation Template URL.orchestration_cfn_template_parameters– AWS CloudFormation Template parameters specified in ruby hash (take a look at example Vagrantfile). This parameter is optional.