Add initial support for Consul environment in Vagrant

Add initial set of files to support building a Consul cluster in
Vagrant.
This commit is contained in:
Scott Lowe 2015-02-09 19:21:41 -07:00
parent 145b578d88
commit ba6dcd676a
6 changed files with 140 additions and 0 deletions

47
consul/Vagrantfile vendored Normal file
View file

@ -0,0 +1,47 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Specify Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
# Require 'yaml' and 'fileutils' modules
require 'yaml'
# Read YAML file with VM details (box, CPU, RAM, IP addresses)
# Be sure to edit servers.yml to provide correct IP addresses
servers = YAML.load_file('servers.yml')
# Define the location of the Consul configuration files
consul_config_dir = "/etc/consul.d/"
# Create and configure the VMs
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Always use Vagrant's default insecure key
config.ssh.insert_key = false
# 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
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

View file

@ -0,0 +1,37 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Specify Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
# Create and configure the VMs
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Always use Vagrant's default insecure key
config.ssh.insert_key = false
# Use an Ubuntu 14.04 x64 base box created for the vmware_fusion provider
config.vm.box = "slowe/ubuntu-trusty-x64"
# Assign a static IP address to the private network
config.vm.network "private_network", ip: "192.168.1.101"
# Disable automatic box update checking
config.vm.box_check_update = false
# Disable default shared folder
config.vm.synced_folder ".", "/vagrant", disabled: true
# Configure the VM's RAM and vCPUs
config.vm.provider :vmware_fusion do |vmw|
vmw.vmx["memsize"] = "512"
vmw.vmx["numvcpus"] = "1"
end
# Provision and configure the VM
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end

8
consul/bootstrap.json Normal file
View file

@ -0,0 +1,8 @@
{
"bootstrap": true,
"server": true,
"datacenter": "dc1",
"data_dir": "/tmp",
"log_level": "INFO",
"enable_syslog": true
}

20
consul/consul.sh Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
# Update list of packages
sudo apt-get update
# Install unzip package, needed to decompress Consul download
sudo apt-get -y install unzip
# Get Consul download
wget https://dl.bintray.com/mitchellh/consul/0.4.1_linux_amd64.zip
# Decompress and remove Consul download
unzip 0.4.1_linux_amd64.zip
rm 0.4.1_linux_amd64.zip
# Move Consul binary to location in path
sudo mv consul /usr/local/bin/
# Create directories needed by Consul
sudo mkdir -p /etc/consul.d/{bootstrap,server}

9
consul/server.json Normal file
View file

@ -0,0 +1,9 @@
{
"bootstrap": false,
"server": true,
"datacenter": "dc1",
"data_dir": "/tmp",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["192.168.1.101", "192.168.1.102", "192.168.1.103"]
}

19
consul/servers.yml Normal file
View file

@ -0,0 +1,19 @@
---
- name: consul-01
box: slowe/ubuntu-trusty-x64
ram: 512
vcpu: 1
priv_ip: 192.168.1.101
script: consul-01.sh
- name: consul-02
box: slowe/ubuntu-trusty-x64
ram: 512
vcpu: 1
priv_ip: 192.168.1.102
script: consul-02.sh
- name: consul-03
box: slowe/ubuntu-trusty-x64
ram: 512
vcpu: 1
priv_ip: 192.168.1.103
script: consul-03.sh