Skip to content

Instantly share code, notes, and snippets.

@SuperSandeep
Forked from v6/Vagrantfile
Created October 30, 2018 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuperSandeep/a11d9daa4a405ab220cd27525ec3f581 to your computer and use it in GitHub Desktop.
Save SuperSandeep/a11d9daa4a405ab220cd27525ec3f581 to your computer and use it in GitHub Desktop.
// , Nathan's Vagrantfile for a Disposable Simple Consul server for ACL troubleshooting
# -*- mode: ruby -*-
# vi: set ft=ruby :
 
$script = <<SCRIPT
echo "THIS WILL MAKE A VM WITH 1 CONSUL RUNNING IN SERVER MODE, AND ANOTHER RUNNING IN CLIENT MODE"
echo "Installing dependencies on the new VM created by Vagrant ..."
sudo apt-get update
sudo apt-get install -y unzip curl jq dnsutils
 
echo "Determining Consul version to install on the VM created by Vagrant ..."
CHECKPOINT_URL="https://checkpoint-api.hashicorp.com/v1/check"
if [ -z "$CONSUL_DEMO_VERSION" ]; then
    CONSUL_DEMO_VERSION=$(curl -s "${CHECKPOINT_URL}"/consul | jq .current_version | tr -d '"')
fi
 
echo "Fetching Consul version ${CONSUL_DEMO_VERSION} for the VM created by Vagrant ..."
cd /tmp/
curl -s https://releases.hashicorp.com/consul/${CONSUL_DEMO_VERSION}/consul_${CONSUL_DEMO_VERSION}_linux_amd64.zip -o consul.zip
 
echo "Installing Consul version ${CONSUL_DEMO_VERSION} on the new VM ..."
unzip consul.zip
sudo chmod +x consul
sudo mv consul /usr/bin/consul
 
sudo mkdir /etc/consul.d
sudo chmod a+w /etc/consul.d
echo "IP addresses for the new VMs are: 172.20.20.20 and 172.20.20.30"
 
SCRIPT
 
# Specify a Consul version
CONSUL_DEMO_VERSION = ENV['CONSUL_DEMO_VERSION']
 
# Specify a custom Vagrant box for the demo
DEMO_BOX_NAME = ENV['DEMO_BOX_NAME'] || "debian/stretch64"
 
# Vagrantfile API/syntax version.
# NB: Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
 
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = DEMO_BOX_NAME
 
  config.vm.provision "shell",
                          inline: $script,
                          env: {'CONSUL_DEMO_VERSION' => CONSUL_DEMO_VERSION}
 
  config.vm.define "n1" do |n1|
      n1.vm.hostname = "n1"
      n1.vm.network "private_network", ip: "172.20.20.20"
  end
 
  config.vm.define "n2" do |n2|
      n2.vm.hostname = "n2"
      n2.vm.network "private_network", ip: "172.20.20.30"
  end
end
@v6
Copy link

v6 commented Oct 30, 2018

// , Thanks for fixing my Syntax Error, @SuperSandeep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment