Created
March 19, 2013 00:32
-
-
Save kesor/5192456 to your computer and use it in GitHub Desktop.
Vagrant configuration to install two Ubuntu 12.04 servers, first server has a Chef Server installed, second server has a Chef Client installed, and the folder where these files are places is configured to be a Chef Workstation using admin.pem.
This file contains hidden or 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
source "https://rubygems.org" | |
gem 'chef', '>= 11.0' | |
gem 'librarian' | |
gem 'vagrant', '= 1.0.6' | |
gem 'vagrant-hostmaster' | |
gem 'foodcritic' |
This file contains hidden or 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 : | |
# default box when no VAGRANT_BOX / VAGRANT_BOX_URL environment is set | |
BOX_NAME = "precise" | |
BOX_URL = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box" | |
UBUNTU_CLEAN_IMAGE = <<-EOF | |
#!/bin/sh | |
apt-get remove puppet libruby1.8 libshadow-ruby1.8 ruby1.8 ruby1.8-dev rubygems -y | |
apt-get autoremove -y | |
EOF | |
CHEF_CLIENT_INSTALL = <<-EOF | |
#!/bin/sh | |
test -d /opt/chef || { | |
echo "Installing chef-client via omnibus" | |
curl -L -s https://www.opscode.com/chef/install.sh | bash | |
} | |
EOF | |
CHEF_SERVER_INSTALL = <<-EOF | |
#!/bin/sh | |
test -d /opt/chef-server || { | |
echo "Installing chef-server via omnibus" | |
curl -L -s 'http://www.opscode.com/chef/download-server?p=ubuntu&pv=12.04&m=x86_64' > chef-server.dpkg | |
dpkg -i chef-server.dpkg | |
/opt/chef-server/bin/chef-server-ctl reconfigure >/dev/null | |
} | |
EOF | |
CHEF_CREATE_WORKSTATION = <<-EOF | |
#!/bin/sh | |
mkdir -p /vagrant/.chef | |
cp /etc/chef-server/admin.pem /vagrant/.chef/ | |
cp /etc/chef-server/chef-validator.pem /vagrant/.chef/ | |
cat <<EOK > /vagrant/.chef/knife.rb | |
cwd = File.dirname(__FILE__) | |
log_level :info # valid values - :debug :info :warn :error :fatal | |
log_location STDOUT | |
node_name ENV.fetch('KNIFE_NODE_NAME', 'admin') | |
client_key ENV.fetch('KNIFE_CLIENT_KEY', File.join(cwd,'admin.pem')) | |
chef_server_url ENV.fetch('KNIFE_CHEF_SERVER_URL', 'https://chefserver.vagrant') | |
validation_client_name ENV.fetch('KNIFE_CHEF_VALIDATION_CLIENT_NAME', 'chef-validator') | |
validation_key ENV.fetch('KNIFE_CHEF_VALIDATION_KEY', File.join(cwd,'chef-validator.pem')) | |
syntax_check_cache_path File.join(cwd,'syntax_check_cache') | |
cookbook_path [File.join(cwd,'..','cookbooks'), File.join(cwd,'..','site-cookbooks')] | |
data_bag_path File.join(cwd,'..','data_bags') | |
role_path File.join(cwd,'..','roles') | |
EOK | |
EOF | |
CHEF_CLIENT_PROVISION = lambda do |chef| | |
chef.chef_server_url = 'https://chefserver.vagrant' | |
chef.validation_key_path = ".chef/chef-validator.pem" | |
chef.validation_client_name = "chef-validator" | |
end | |
Vagrant::Config.run do |config| | |
config.vm.box = ENV.fetch("VAGRANT_BOX", BOX_NAME) | |
config.vm.box_url = ENV.fetch("VAGRANT_BOX_URL", BOX_URL) | |
if ENV.fetch('VAGRANT_GUI', false) | |
config.vm.boot_mode = :gui | |
end | |
config.vm.define :chefserver do |v| | |
v.vm.customize ["modifyvm", :id, "--memory", 1024] | |
v.vm.network :hostonly, "192.168.34.10" | |
v.vm.host_name = "chefserver.vagrant" | |
v.vm.provision :shell, :inline => UBUNTU_CLEAN_IMAGE | |
v.vm.provision :shell, :inline => CHEF_CLIENT_INSTALL | |
v.vm.provision :shell, :inline => CHEF_SERVER_INSTALL | |
v.vm.provision :shell, :inline => CHEF_CREATE_WORKSTATION | |
end | |
config.vm.define 'client' do |v| | |
v.vm.network :hostonly, "192.168.34.30" | |
v.vm.forward_port 22, 2230 | |
v.vm.host_name = "client.vagrant" | |
v.vm.provision :shell, :inline => UBUNTU_CLEAN_IMAGE | |
v.vm.provision :shell, :inline => CHEF_CLIENT_INSTALL | |
v.vm.provision :chef_client, &CHEF_CLIENT_PROVISION | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment