Skip to content

Instantly share code, notes, and snippets.

@0x3bfc
Last active August 29, 2015 14:25
Show Gist options
  • Save 0x3bfc/63de3eab27c3f71ecd52 to your computer and use it in GitHub Desktop.
Save 0x3bfc/63de3eab27c3f71ecd52 to your computer and use it in GitHub Desktop.
Vagrant file for Multiple Instances on GCE
# Customize these global variables
$GOOGLE_PROJECT_ID = "MYPROJECTID"
$GOOGLE_CLIENT_EMAIL = "[email protected]"
$GOOGLE_JSON_KEY_LOCATION = "/home/ubuntu/.ssh/privatekey-gce.json"
$LOCAL_USER = "ubuntu"
$LOCAL_SSH_KEY = "/home/ubuntu/.ssh/id_rsa"
# Example Debian provistion script
$PROVISION_DEBIAN = <<SCRIPT
uname=$(uname -a)
ver=$(cat /etc/debian_version)
echo "== BEGIN: vagrant provisioning on '${uname}'"
echo "== DEBIAN VERSION: ${ver}"
echo "== UPDATING Debian repositories and packages"
/usr/bin/apt-get update -y -qq > /dev/null 2>&1
/usr/bin/apt-get upgrade -y -qq > /dev/null 2>&1
extip=$(curl -s http://bot.whatismyipaddress.com)
echo "== EXTERNAL IP: ${extip}"
echo "== APPENDING /etc/motd"
d=$(date +%r)
echo "# ${d}" >> /etc/motd
echo "== cat /etc/motd"
cat /etc/motd
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "gce"
config.vm.provision :shell, :inline => $PROVISION_DEBIAN
config.vm.define :z1c do |z1c|
z1c.vm.provider :google do |google, override|
google.google_project_id = $GOOGLE_PROJECT_ID
google.google_client_email = $GOOGLE_CLIENT_EMAIL
google.google_json_key_location = $GOOGLE_JSON_KEY_LOCATION
google.zone = "us-central1-c"
override.ssh.username = $LOCAL_USER
override.ssh.private_key_path = $LOCAL_SSH_KEY
google.zone_config "us-central1-c" do |z1c_zone|
z1c_zone.name = "master"
z1c_zone.image = "debian-7-wheezy-v20150603"
z1c_zone.machine_type = "f1-micro"
z1c_zone.zone = "us-central1-c"
z1c_zone.metadata = {"zone" => "US Central 1c", "sshKeys" => ["ssh-rsa AAAAB3NXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ubuntu@cis5"]}
end
end
end
config.vm.define :z1f do |z1f|
z1f.vm.provider :google do |google, override|
google.google_project_id = $GOOGLE_PROJECT_ID
google.google_client_email = $GOOGLE_CLIENT_EMAIL
google.google_json_key_location = $GOOGLE_JSON_KEY_LOCATION
google.zone = "us-central1-c"
override.ssh.username = $LOCAL_USER
override.ssh.private_key_path = $LOCAL_SSH_KEY
google.zone_config "us-central1-c" do |z1f_zone|
z1f_zone.name = "node-1"
z1f_zone.image = "debian-7-wheezy-v20150603"
z1f_zone.machine_type = "f1-micro"
z1f_zone.zone = "us-central1-c"
z1f_zone.metadata = {"zone" => "US Central 1c", "sshKeys" => ["ssh-rsa AAAAB3NXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ubuntu@cis5"]}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment