Skip to content

Instantly share code, notes, and snippets.

@lancehudson
Created December 1, 2015 18:58
Show Gist options
  • Save lancehudson/3826cd32577a87c6b83a to your computer and use it in GitHub Desktop.
Save lancehudson/3826cd32577a87c6b83a to your computer and use it in GitHub Desktop.
Docker-Machine with VPN
# -*- mode: ruby -*-
# vi: set ft=ruby :
required_plugins = %w( vagrant-triggers vagrant-persistent-storage )
required_plugins.each do |plugin|
system "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin
end
IP = "192.168.50.4"
NAME = "default"
VPN_GROUP = "Dev"
VPN_USER = "XXX"
VPN_SERVER = "XXX"
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: IP, nictype: "virtio"
config.vm.provider "virtualbox" do |v|
v.name = "docker"
v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
end
config.persistent_storage.enabled = true
config.persistent_storage.location = ".vagrant/docker.vdi"
config.persistent_storage.size = 500 * 1024
config.persistent_storage.mountname = 'docker'
config.persistent_storage.filesystem = 'ext4'
config.persistent_storage.mountpoint = '/var/lib/docker'
config.persistent_storage.use_lvm = false
config.persistent_storage.mountoptions = ['noatime' ,'nobarrier']
config.trigger.after :destroy do
info "Removing Machine from Docker-Machine"
run "docker-machine rm #{NAME}"
end
config.trigger.after :up do
info "Adding Machine to Docker-Machine"
run "docker-machine create -d generic --generic-ssh-user vagrant --generic-ssh-key .vagrant/machines/default/virtualbox/private_key --generic-ip-address #{IP} #{NAME}"
end
config.vm.provision "shell", inline: <<SCRIPT
echo I am provisioning...
date > /etc/vagrant_provisioned_at
apt-get update
apt-get install -y openconnect
echo "#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo #{VPN.password()} | openconnect -u #{VPN_USER} --authgroup #{VPN_GROUP} --passwd-on-stdin -b #{VPN_SERVER}
exit 0" > /etc/rc.local
/etc/init.d/rc.local start
SCRIPT
end
module VPN
def self.password
begin
system 'stty -echo'
print 'VPN Password: '
; pass = $stdin.gets.chomp; puts "\n"
ensure
system 'stty echo'
end
pass
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment