From 17947667d2b344ebccef248115102d88f755b465 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Wed, 7 Oct 2015 19:41:10 -0600 Subject: [PATCH 1/3] Start update of Consul environment Update Vagrantfile with AppCatalyst support. Clean up YAML file with VM information. --- consul/Vagrantfile | 24 ++++++++++++++++++++---- consul/servers.yml | 16 ++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/consul/Vagrantfile b/consul/Vagrantfile index 285f454..28cccdd 100644 --- a/consul/Vagrantfile +++ b/consul/Vagrantfile @@ -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 \ No newline at end of file + 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 diff --git a/consul/servers.yml b/consul/servers.yml index 2e78c31..ebe79e9 100644 --- a/consul/servers.yml +++ b/consul/servers.yml @@ -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 From 028bc1bd4be9e255a61c76b50248e81eaf84585c Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Wed, 7 Oct 2015 23:05:37 -0600 Subject: [PATCH 2/3] Start work on multi-instance OpenStack files Add new Vagrantfile with multi-instance support. Modify external data file (instances.yml) accordingly. --- vagrant-openstack-multi/README.md | 40 +++++++++++++++++ vagrant-openstack-multi/Vagrantfile | 60 +++++++++++++++++++++++++ vagrant-openstack-multi/credentials.yml | 4 ++ vagrant-openstack-multi/instances.yml | 15 +++++++ 4 files changed, 119 insertions(+) create mode 100644 vagrant-openstack-multi/README.md create mode 100644 vagrant-openstack-multi/Vagrantfile create mode 100644 vagrant-openstack-multi/credentials.yml create mode 100644 vagrant-openstack-multi/instances.yml diff --git a/vagrant-openstack-multi/README.md b/vagrant-openstack-multi/README.md new file mode 100644 index 0000000..96ff6b7 --- /dev/null +++ b/vagrant-openstack-multi/README.md @@ -0,0 +1,40 @@ +# 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. + +## 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 `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 +3. 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 specify the correct URL for authenticating with OpenStack + * You must provide the correct path for the private key that matches the keypair specified in `instances.yml` + * You must supply the list of security groups that OpenStack should apply to the new instance +4. Ensure that the system running Vagrant has connectivity to the authentication URL for OpenStack. +5. 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! + +## Planned Enhancements + +* Changing the `Vagrantfile` to allow for multi-instance configurations +* Removing all user-specific parameters from the `Vagrantfile` so that no edits are required diff --git a/vagrant-openstack-multi/Vagrantfile b/vagrant-openstack-multi/Vagrantfile new file mode 100644 index 0000000..722122f --- /dev/null +++ b/vagrant-openstack-multi/Vagrantfile @@ -0,0 +1,60 @@ +# -*- 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') +instances = YAML.load_file('instances.yml') + +# Specify Vagrant version and Vagrant API version +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://cloud.lowehome.net: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 + config.ssh.private_key_path = '~/.ssh/homelab.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' + 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 diff --git a/vagrant-openstack-multi/credentials.yml b/vagrant-openstack-multi/credentials.yml new file mode 100644 index 0000000..57016bf --- /dev/null +++ b/vagrant-openstack-multi/credentials.yml @@ -0,0 +1,4 @@ +--- +username: "slowe" +password: "Me3twet8ein" +tenant: "lab" diff --git a/vagrant-openstack-multi/instances.yml b/vagrant-openstack-multi/instances.yml new file mode 100644 index 0000000..343832a --- /dev/null +++ b/vagrant-openstack-multi/instances.yml @@ -0,0 +1,15 @@ +--- +- name: "test-01" + flavor: "m1.small" + image: "Ubuntu 14.04.3 LTS x64" + ip_pool: "ext-net-1" + networks: "test-01" + keypair: "homelab" + ssh_user: "ubuntu" +- name: "test-02" + flavor: "m1.small" + image: "Ubuntu 12.04.5 LTS x64" + ip_pool: "ext-net-1" + networks: "test-01" + keypair: "homelab" + ssh_user: "ubuntu" From 2f852dabb823e52cd0aee64c1d817cdbed288b10 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Thu, 8 Oct 2015 09:02:41 -0600 Subject: [PATCH 3/3] Finalize multi-instance Vagrant and OpenStack environment Update README.md with final information. Add comments to Vagrantfile for better understanding and troubleshooting. Sanitize all files. --- vagrant-openstack-multi/README.md | 27 +++++++++++++------------ vagrant-openstack-multi/Vagrantfile | 10 ++++++--- vagrant-openstack-multi/credentials.yml | 6 +++--- vagrant-openstack-multi/instances.yml | 8 ++++---- vagrant-openstack/README.md | 9 ++++----- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/vagrant-openstack-multi/README.md b/vagrant-openstack-multi/README.md index 96ff6b7..84119f5 100644 --- a/vagrant-openstack-multi/README.md +++ b/vagrant-openstack-multi/README.md @@ -10,14 +10,20 @@ These files were created to allow users to use Vagrant ([http://www.vagrantup.co * **README.md**: The file you're currently reading. -* **Vagrantfile**: This file is used by Vagrant to spin up the OpenStack instance. +* **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 `instances.yml`. The fields in this YAML file is fairly straightforward, but here's a quick breakdown: + +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 @@ -25,16 +31,11 @@ Please note that you'll need a working OpenStack installation in order to use th * 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 -3. 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 specify the correct URL for authenticating with OpenStack - * You must provide the correct path for the private key that matches the keypair specified in `instances.yml` - * You must supply the list of security groups that OpenStack should apply to the new instance -4. Ensure that the system running Vagrant has connectivity to the authentication URL for OpenStack. -5. 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. + +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! - -## Planned Enhancements - -* Changing the `Vagrantfile` to allow for multi-instance configurations -* Removing all user-specific parameters from the `Vagrantfile` so that no edits are required diff --git a/vagrant-openstack-multi/Vagrantfile b/vagrant-openstack-multi/Vagrantfile index 722122f..9b04cb5 100644 --- a/vagrant-openstack-multi/Vagrantfile +++ b/vagrant-openstack-multi/Vagrantfile @@ -7,16 +7,18 @@ 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 and Vagrant API version +# 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://cloud.lowehome.net:5000/v2.0' +ENV['OS_AUTH_URL'] = 'http://controller:5000/v2.0' # Create and configure the OpenStack instance(s) Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| @@ -25,7 +27,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # config.vm.box = "dummy" # Specify path to SSH private key - config.ssh.private_key_path = '~/.ssh/homelab.pem' + # 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| @@ -39,6 +42,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 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' diff --git a/vagrant-openstack-multi/credentials.yml b/vagrant-openstack-multi/credentials.yml index 57016bf..571a8ba 100644 --- a/vagrant-openstack-multi/credentials.yml +++ b/vagrant-openstack-multi/credentials.yml @@ -1,4 +1,4 @@ --- -username: "slowe" -password: "Me3twet8ein" -tenant: "lab" +username: "demo" +password: "demo" +tenant: "demo" diff --git a/vagrant-openstack-multi/instances.yml b/vagrant-openstack-multi/instances.yml index 343832a..2a2dd7c 100644 --- a/vagrant-openstack-multi/instances.yml +++ b/vagrant-openstack-multi/instances.yml @@ -2,14 +2,14 @@ - name: "test-01" flavor: "m1.small" image: "Ubuntu 14.04.3 LTS x64" - ip_pool: "ext-net-1" - networks: "test-01" + 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: "ext-net-1" - networks: "test-01" + ip_pool: "public" + networks: "test" keypair: "homelab" ssh_user: "ubuntu" diff --git a/vagrant-openstack/README.md b/vagrant-openstack/README.md index 16dfb19..11c0046 100644 --- a/vagrant-openstack/README.md +++ b/vagrant-openstack/README.md @@ -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.