diff --git a/consul/Vagrantfile b/consul/Vagrantfile new file mode 100644 index 0000000..0c28d3d --- /dev/null +++ b/consul/Vagrantfile @@ -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 \ No newline at end of file diff --git a/consul/Vagrantfile-single-box b/consul/Vagrantfile-single-box new file mode 100644 index 0000000..62c13eb --- /dev/null +++ b/consul/Vagrantfile-single-box @@ -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 diff --git a/consul/bootstrap.json b/consul/bootstrap.json new file mode 100644 index 0000000..1a40c73 --- /dev/null +++ b/consul/bootstrap.json @@ -0,0 +1,8 @@ +{ + "bootstrap": true, + "server": true, + "datacenter": "dc1", + "data_dir": "/tmp", + "log_level": "INFO", + "enable_syslog": true +} \ No newline at end of file diff --git a/consul/consul.sh b/consul/consul.sh new file mode 100644 index 0000000..aeed3fd --- /dev/null +++ b/consul/consul.sh @@ -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} diff --git a/consul/server.json b/consul/server.json new file mode 100644 index 0000000..3b301ad --- /dev/null +++ b/consul/server.json @@ -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"] +} \ No newline at end of file diff --git a/consul/servers.yml b/consul/servers.yml new file mode 100644 index 0000000..3878dc8 --- /dev/null +++ b/consul/servers.yml @@ -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