Last active
August 29, 2015 14:24
-
-
Save stathy/92f2089bb81148fa49f2 to your computer and use it in GitHub Desktop.
Sample cluster vagrant file
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 -*- | |
# vi: set ft=ruby : | |
Vagrant::Config.run do |config| | |
{ | |
:lb => { | |
:ip => '192.168.65.50', | |
:memory => 512, | |
:roles => %w( lb ) | |
}, | |
:m1 => { | |
:ip => '192.168.65.90', | |
:memory => 1512, | |
:roles => %w( master ) | |
}, | |
:m2 => { | |
:ip => '192.168.65.95', | |
:memory => 1512, | |
:roles => %w( master ) | |
}, | |
:m3 => { | |
:ip => '192.168.65.101', | |
:memory => 1512, | |
:roles => %w( master ) | |
}, | |
:w1 => { | |
:ip => '192.168.65.111', | |
:memory => 1256, | |
:roles => %w( slave ) | |
}, | |
:w2 => { | |
:ip => '192.168.65.120', | |
:memory => 1256, | |
:roles => %w( slave ) | |
}, | |
:w3 => { | |
:ip => '192.168.65.121', | |
:memory => 1256, | |
:roles => %w( slave ) | |
}, | |
:w4 => { | |
:ip => '192.168.65.131', | |
:memory => 1256, | |
:roles => %w( slave ) | |
}, | |
:w5 => { | |
:ip => '192.168.65.141', | |
:memory => 1256, | |
:roles => %w( slave ) | |
}, | |
:w6 => { | |
:ip => '192.168.65.151', | |
:memory => 1256, | |
:roles => %w( slave ) | |
}, | |
}.each do |name,cfg| | |
config.vm.define name do |vm_cfg| | |
vm_cfg.vm.host_name = "#{name}" | |
vm_cfg.vm.network :hostonly, cfg[:ip] if cfg[:ip] | |
vm_cfg.vm.box = "opscode-centos-7.1" | |
vm_cfg.vm.customize ["modifyvm", :id, "--name", vm_cfg.vm.host_name] | |
vm_cfg.vm.customize ["modifyvm", :id, "--memory", cfg[:memory]] | |
vm_cfg.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] | |
if cfg[:forwards] | |
cfg[:forwards].each do |from,to| | |
vm_config.vm.forward_port from, to | |
end | |
end | |
vm_cfg.vm.provision "shell", inline: <<-SHELL | |
cd ~vagrant | |
sudo systemctl stop NetworkManager | |
sudo systemctl disable NetworkManager | |
sudo mkdir -p /etc/chef | |
sudo cp /vagrant/client.rb /etc/chef/ | |
sudo cp /vagrant/stathy-validator.pem /etc/chef/ | |
curl -L https://www.chef.io/chef/install.sh > install.sh | |
sudo bash install.sh | |
SHELL | |
end | |
end | |
end | |
__END__ | |
config.vm.provision "shell", inline: <<-SHELL | |
curl -L https://www.chef.io/chef/install.sh | |
sudo install.sh | |
# sudo yum update --y | |
# sudo apt-get install -y apache2 | |
SHELL | |
Vagrant.configure(2) do |config| | |
config.vm.box_url = "opscode-centos-7.1" | |
# config.vm.network "forwarded_port", guest: 80, host: 8080 | |
# config.vm.network "private_network", ip: "192.168.33.10" | |
# config.vm.network "public_network" | |
# config.vm.provider "virtualbox" do |vb| | |
# # Display the VirtualBox GUI when booting the machine | |
# vb.gui = true | |
# | |
# # Customize the amount of memory on the VM: | |
# vb.memory = "1024" | |
# end | |
# https://docs.vagrantup.com/v2/push/atlas.html for more information. | |
# config.push.define "atlas" do |push| | |
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" | |
# end | |
# config.vm.provision "shell", inline: <<-SHELL | |
# sudo apt-get update | |
# sudo apt-get install -y apache2 | |
# SHELL | |
end | |
vm_cfg.vm.provision :chef_client do |chef| | |
chef.chef_server_url = "https://chef.localdomain/organizations/opscode" | |
chef.validation_key_path = "#{ENV['HOME']}/.chef/chef_localdomain-opscode-validator.pem" | |
chef.validation_client_name = "opscode-validator" | |
chef.node_name = vm_cfg.vm.host_name | |
chef.provisioning_path = "/etc/chef" | |
chef.log_level = :info | |
# chef.output = 'doc' | |
chef.environment = chef_env | |
chef.json = cfg[:attr] if cfg[:attr].is_a?(Hash) | |
if cfg[:run_list].nil? then | |
cfg[:roles] ||= [] | |
cfg[:roles].each { |r| chef.add_role(r) } | |
cfg[:recipes] ||= [] | |
cfg[:recipes].each { |r| chef.add_recipe(r) } | |
else | |
chef.run_list = cfg[:run_list] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment