Created
November 7, 2015 19:00
-
-
Save hazelesque/b154829a1297d7eeb73f to your computer and use it in GitHub Desktop.
Example multimachine Vagrantfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vim: set ft=ruby ts=8 sts=2 sw=2 et: | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
unless Vagrant.has_plugin?("landrush") | |
raise 'Cannot continue, landrush is not installed! Run "vagrant plugin install landrush" and try again!' | |
end | |
# CONSTANTS | |
$FIXED_SALT_MASTER_IP = "172.27.0.5" | |
$SRVSALT_UPDATEREV = "feature/infra-sandbox" | |
# HELPER FUNCTION(S) | |
def create_machine(config, hostname_uqdn, region, client, pool, role, salt_master_ip, opts = {}) | |
box = opts[:box] || nil | |
ram = opts[:ram] || 512 | |
is_salt_master = opts[:is_salt_master] || false | |
autostart = opts[:autostart] || false | |
spec_pattern = opts[:spec_pattern] || nil | |
config.vm.define hostname_uqdn, autostart: autostart do |machine| | |
# Box template override | |
unless box.nil? | |
machine.vm.box = box | |
end | |
# RAM override | |
unless ram.nil? | |
machine.vm.provider "virtualbox" do |v| | |
v.memory = ram | |
end | |
end | |
# Hostname (needed for landrush) | |
machine.vm.hostname = "#{hostname_uqdn}.vagrant-sandbox.hazelesque.uk" | |
# Networking | |
if is_salt_master | |
machine.vm.network "private_network", type: "static", ip: $FIXED_SALT_MASTER_IP, netmask: "255.255.255.0" | |
else | |
machine.vm.network "private_network", type: "dhcp", ip: "172.27.0.0", netmask: "255.255.255.0", dhcp_lower: "172.27.0.10", dhcp_upper: "172.27.0.199" | |
end | |
# Provision! | |
machine.vm.provision :shell, :path => "scripts/do_preseed_grains.sh", :args => [region, client, pool, role] | |
machine.vm.provision :shell, :path => "scripts/bootstrap_install_salt.sh" | |
# Gold server specific crap | |
if is_salt_master | |
machine.vm.provision :shell, :path => "scripts/standup_salt_master.sh", :args => [$SRVSALT_UPDATEREV] | |
end | |
machine.vm.provision :shell, :path => "scripts/bootstrap_salt.sh", :args => [salt_master_ip] | |
# Test! | |
# Serverspec tests (vagrant + serverspec + RSpec => BDD for Vagrant) | |
if Vagrant.has_plugin?("vagrant-serverspec") and spec_pattern | |
machine.vm.provision "serverspec-tests", :type => :serverspec do |spec| | |
##spec.pattern = '*_spec.rb' | |
spec.pattern = spec_pattern | |
end | |
end | |
end | |
end | |
# VAGRANT CONFIGURATION | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
#### GLOBAL SETTINGS #### | |
# Default box | |
config.vm.box = "bento/centos-6.7" | |
# Configuration for landrush (DNS management), including static mappings | |
config.landrush.enabled = true | |
config.landrush.tld = 'vagrant-sandbox.hazelesque.uk' | |
config.landrush.host 'example-dns-in-search-domain.vagrant-sandbox.hazelesque.uk', '172.27.0.5' | |
#### MACHINES #### | |
# salt master | |
create_machine(config, "salt-master", "london", "hazelesque", "dev", "salt-master", $FIXED_SALT_MASTER_IP, is_salt_master: true, autostart: true) | |
# shared | |
create_machine(config, "syslog", "london", "hazelesque", "dev", "syslog", $FIXED_SALT_MASTER_IP, autostart: true) | |
## create_machine(config, "mysql", "london", "hazelesque", "dev", "mysql", $FIXED_SALT_MASTER_IP, ram: 1024) | |
create_machine(config, "redis", "london", "hazelesque", "dev", "redis", $FIXED_SALT_MASTER_IP) | |
create_machine(config, "rabbit", "london", "hazelesque", "dev", "rabbit", $FIXED_SALT_MASTER_IP) | |
# xyzcoffee | |
create_machine(config, "xyzcoffee-app", "london", "xyzcoffee", "dev", "app", $FIXED_SALT_MASTER_IP) | |
create_machine(config, "xyzcoffee-admin", "london", "xyzcoffee", "dev", "admin", $FIXED_SALT_MASTER_IP) | |
create_machine(config, "xyzcoffee-celery", "london", "xyzcoffee", "dev", "celery", $FIXED_SALT_MASTER_IP) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment