mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Merge pull request #4 from lowescott/vagrant-openstack-multi
Create multi-instance Vagrant-OpenStack learning environment
This commit is contained in:
commit
c2785bf17d
7 changed files with 156 additions and 17 deletions
24
consul/Vagrantfile
vendored
24
consul/Vagrantfile
vendored
|
|
@ -5,6 +5,8 @@
|
|||
Vagrant.require_version ">= 1.6.0"
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant'
|
||||
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion'
|
||||
#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_appcatalyst'
|
||||
|
||||
# Require 'yaml' module
|
||||
require 'yaml'
|
||||
|
|
@ -22,24 +24,38 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|||
# Iterate through entries in YAML file to create VMs
|
||||
servers.each do |servers|
|
||||
config.vm.define servers["name"] do |srv|
|
||||
|
||||
# Don't check for box updates
|
||||
srv.vm.box_check_update = false
|
||||
|
||||
# Specify hostname and Vagrant box
|
||||
srv.vm.hostname = servers["name"]
|
||||
srv.vm.box = servers["box"]
|
||||
|
||||
# Assign an additional static private network
|
||||
srv.vm.network "private_network", ip: servers["priv_ip"]
|
||||
|
||||
# Specify default synced folder; requires VMware Tools
|
||||
srv.vm.synced_folder ".", "/vagrant"
|
||||
|
||||
# Provision consul to the VMs
|
||||
srv.vm.provision "shell", path: "consul.sh"
|
||||
|
||||
# Copy in the Consul configuration files
|
||||
srv.vm.provision "file", source: "bootstrap.json", destination: "/etc/consul.d/bootstrap/config.json"
|
||||
srv.vm.provision "file", source: "server.json", destination: "/etc/consul.d/server/config.json"
|
||||
|
||||
# Configure VMs with RAM and CPUs per settings in servers.yml
|
||||
srv.vm.provider :vmware_fusion do |vmw|
|
||||
vmw.vmx["memsize"] = servers["ram"]
|
||||
vmw.vmx["numvcpus"] = servers["vcpu"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end # srv.vm.provider vmware_fusion
|
||||
|
||||
# Configure VMs with RAM and CPUs per settings in servers.yml
|
||||
srv.vm.provider :vmware_appcatalyst do |vmw|
|
||||
vmw.vmx["memsize"] = servers["ram"]
|
||||
vmw.vmx["numvcpus"] = servers["vcpu"]
|
||||
end # srv.vm.provider vmware_fusion
|
||||
end # config.vm.define
|
||||
end # servers.each
|
||||
end # Vagrant.configure
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
---
|
||||
- name: consul-01
|
||||
box: slowe/ubuntu-trusty-x64
|
||||
ram: 512
|
||||
vcpu: 1
|
||||
- name: "consul-01"
|
||||
box: "slowe/ubuntu-trusty-x64"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
priv_ip: 192.168.1.101
|
||||
- name: consul-02
|
||||
box: slowe/ubuntu-trusty-x64
|
||||
ram: 512
|
||||
vcpu: 1
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
priv_ip: 192.168.1.102
|
||||
- name: consul-03
|
||||
box: slowe/ubuntu-trusty-x64
|
||||
ram: 512
|
||||
vcpu: 1
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
priv_ip: 192.168.1.103
|
||||
|
|
|
|||
41
vagrant-openstack-multi/README.md
Normal file
41
vagrant-openstack-multi/README.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# Using Vagrant with OpenStack (Multiple Instances)
|
||||
|
||||
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) with OpenStack ([http://www.openstack.org](http://www.openstack.org)), where the VMs managed by Vagrant are instances in an OpenStack cloud. This configuration supports Vagrant operations against multiple instances, and was tested using Vagrant 1.7.4, version 0.7.0 of [the vagrant-openstack-provider plugin](https://github.com/ggiamarchi/vagrant-openstack-provider), and the "Juno" release of OpenStack.
|
||||
|
||||
## Contents
|
||||
|
||||
* **credentials.yml**: This YAML file contains the username, password, and tenant name for authenticating against OpenStack. You **must** edit this file to specify the correct information for your OpenStack installation.
|
||||
|
||||
* **instances.yml**: This YAML file contains the instance-specific information for the instance that will be created in OpenStack. You **must** edit this file to specify the correct instance name (as shown in the OpenStack Dashboard), flavor, image, floating IP pool, network name, SSH keypair name, and SSH username. _Failure to edit this file may result in errors trying to run Vagrant._
|
||||
|
||||
* **README.md**: The file you're currently reading.
|
||||
|
||||
* **Vagrantfile**: This file is used by Vagrant to spin up the OpenStack instance. You **must** edit this file to specify the correct URL for use with your OpenStack installation.
|
||||
|
||||
## Instructions
|
||||
|
||||
Please note that you'll need a working OpenStack installation in order to use these files.
|
||||
|
||||
1. Edit `credentials.yml` to supply a valid username, password, and tenant name for your particular OpenStack installation.
|
||||
|
||||
2. Edit `Vagrantfile` and look for comments stating "Edit the following line with your correct information". There are **three** changes you must make in the `Vagrantfile`:
|
||||
* You must set the correct URL for use with your OpenStack installation (see line 21 of `Vagrantfile`).
|
||||
* You must set the correct path and filename for the SSH private key to use with the OpenStack instances (see line 31 of `Vagrantfile`)
|
||||
* You must verify the names of the security groups specified for use with the OpenStack instances (see line 46 of `Vagrantfile`).
|
||||
|
||||
3. Edit `instances.yml`. The fields in this YAML file is fairly straightforward, but here's a quick breakdown:
|
||||
* A display name for the instance ("name")
|
||||
* The name of an OpenStack flavor ("flavor"), which you can obtain using `nova flavor-list`
|
||||
* The name of an OpenStack image ("image"), obtainable via the `glance image-list` command
|
||||
* The name of a floating IP pool ("ip_pool")
|
||||
* The name of the tenant network to which the new instance should be attached ("networks")
|
||||
* The SSH keypair that OpenStack should inject into the instance ("keypair")
|
||||
* The username Vagrant can use to log into the instance ("ssh_user"); this will vary from image to image
|
||||
|
||||
4. If you wish to spin up additional instances, add stanzas to the `instances.yml` file, making sure to observe the correct YAML syntax.
|
||||
|
||||
5. Ensure that the system running Vagrant has connectivity to the authentication URL for OpenStack.
|
||||
|
||||
6. Run `vagrant up` to have Vagrant authenticate to OpenStack and create the desired instance for you. Once the instance is created, you can use `vagrant ssh` to connect to the instance, and `vagrant destroy` will terminate (destroy) the OpenStack instance for you.
|
||||
|
||||
Enjoy!
|
||||
64
vagrant-openstack-multi/Vagrantfile
vendored
Normal file
64
vagrant-openstack-multi/Vagrantfile
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Require the OpenStack provider plugin and YAML module
|
||||
require 'vagrant-openstack-provider'
|
||||
require 'yaml'
|
||||
|
||||
# Read YAML file with OpenStack credentials
|
||||
creds = YAML.load_file('credentials.yml')
|
||||
|
||||
# Read YAML file with instance information
|
||||
instances = YAML.load_file('instances.yml')
|
||||
|
||||
# Specify Vagrant version, Vagrant API version, and Vagrant provider
|
||||
Vagrant.require_version '>= 1.6.0'
|
||||
VAGRANTFILE_API_VERSION = '2'
|
||||
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'openstack'
|
||||
|
||||
# Specify OpenStack authentication URL
|
||||
# Edit the following line with your correct information
|
||||
ENV['OS_AUTH_URL'] = 'http://controller:5000/v2.0'
|
||||
|
||||
# Create and configure the OpenStack instance(s)
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
# No Vagrant box needed with OpenStack
|
||||
# config.vm.box = "dummy"
|
||||
|
||||
# Specify path to SSH private key
|
||||
# Edit the following line with your correct information
|
||||
config.ssh.private_key_path = '~/.ssh/keypair.pem'
|
||||
|
||||
# Configure the base information for the OpenStack provider
|
||||
config.vm.provider 'openstack' do |os|
|
||||
os.openstack_auth_url = ENV['OS_AUTH_URL']
|
||||
os.username = creds['username']
|
||||
os.password = creds['password']
|
||||
os.tenant_name = creds['tenant']
|
||||
os.server_name = 'default'
|
||||
os.flavor = 'm1.small'
|
||||
os.image = 'default'
|
||||
os.floating_ip_pool = 'default'
|
||||
os.networks = 'default'
|
||||
os.keypair_name = 'default'
|
||||
# Edit the following line with your correct information
|
||||
os.security_groups = ['default']
|
||||
os.sync_method = 'none'
|
||||
end # config.vm.provider 'openstack'
|
||||
|
||||
# Loop through YAML file and set per-instance information
|
||||
instances.each do |instance|
|
||||
config.vm.define instance['name'] do |srv|
|
||||
srv.vm.provider 'openstack' do |os, override|
|
||||
os.server_name = instance['name']
|
||||
os.flavor = instance['flavor']
|
||||
os.image = instance['image']
|
||||
os.floating_ip_pool = instance['ip_pool']
|
||||
os.networks = instance['networks']
|
||||
os.keypair_name = instance['keypair']
|
||||
override.ssh.username = instance['ssh_user']
|
||||
end # srv.vm.provider
|
||||
end # config.vm.define
|
||||
end # instances.each
|
||||
end # Vagrant.configure
|
||||
4
vagrant-openstack-multi/credentials.yml
Normal file
4
vagrant-openstack-multi/credentials.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
username: "demo"
|
||||
password: "demo"
|
||||
tenant: "demo"
|
||||
15
vagrant-openstack-multi/instances.yml
Normal file
15
vagrant-openstack-multi/instances.yml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
- name: "test-01"
|
||||
flavor: "m1.small"
|
||||
image: "Ubuntu 14.04.3 LTS x64"
|
||||
ip_pool: "public"
|
||||
networks: "test"
|
||||
keypair: "homelab"
|
||||
ssh_user: "ubuntu"
|
||||
- name: "test-02"
|
||||
flavor: "m1.small"
|
||||
image: "Ubuntu 12.04.5 LTS x64"
|
||||
ip_pool: "public"
|
||||
networks: "test"
|
||||
keypair: "homelab"
|
||||
ssh_user: "ubuntu"
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Using Vagrant with OpenStack
|
||||
# Using Vagrant with OpenStack (Single Instance)
|
||||
|
||||
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to automate the provisioning and de-provisioning of OpenStack instances. This configuration was tested using Vagrant 1.7.4, version 0.7.0 of [the vagrant-openstack-provider plugin](https://github.com/ggiamarchi/vagrant-openstack-provider), and OpenStack "Juno".
|
||||
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) with OpenStack, where the VMs managed by Vagrant are actually instances in an OpenStack cloud. Using these files, Vagrant can only operate against a single instance at a time. This configuration was tested using Vagrant 1.7.4, version 0.7.0 of [the vagrant-openstack-provider plugin](https://github.com/ggiamarchi/vagrant-openstack-provider), and OpenStack "Juno".
|
||||
|
||||
## Contents
|
||||
|
||||
|
|
@ -34,7 +34,6 @@ Note that you'll need a working OpenStack installation in order to use these fil
|
|||
|
||||
Enjoy!
|
||||
|
||||
## Planned Enhancements
|
||||
## Additional Notes
|
||||
|
||||
* Changing the `Vagrantfile` to allow for multi-instance configurations
|
||||
* Removing all user-specific parameters from the `Vagrantfile` so that no edits are required
|
||||
This environment will only create a single instance on OpenStack using Vagrant. If you wish to use Vagrant to create/manage multiple instances, please see the "vagrant-openstack-multi" directory in this repository instead.
|
||||
|
|
|
|||
Loading…
Reference in a new issue