Skip to content

Instantly share code, notes, and snippets.

@tknerr
Created July 22, 2014 09:40
Show Gist options
  • Select an option

  • Save tknerr/6b60316b19835a0935ef to your computer and use it in GitHub Desktop.

Select an option

Save tknerr/6b60316b19835a0935ef to your computer and use it in GitHub Desktop.
Setting up N load-balanced apaches in 42 lines of Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "chef/ubuntu-12.04"
# load balancer VM
config.vm.define "lb" do |lb_config|
lb_config.vm.network "private_network", ip: "192.168.40.90"
lb_config.vm.provision "shell", inline: <<-EOF
sudo apt-get update
sudo apt-get install nginx -y
cat << CONF > /etc/nginx/sites-available/default
upstream backend {
server 192.168.40.91;
server 192.168.40.92;
}
server {
location / {
proxy_pass http://backend;
}
}
CONF
sudo service nginx restart
EOF
end
# web server VMs
(1..2).each do |i|
config.vm.define "web-#{i}" do |web_config|
web_config.vm.network "private_network", ip: "192.168.40.9#{i}"
web_config.vm.provision "shell", inline: <<-EOF
sudo apt-get update
sudo apt-get install apache2 -y
cat << HTML > /var/www/index.html
<html>
<body>Web server #{i}</body>
</html>
HTML
EOF
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment