Skip to content

Instantly share code, notes, and snippets.

@anaynayak
Created August 19, 2013 16:47
Show Gist options
  • Save anaynayak/6271234 to your computer and use it in GitHub Desktop.
Save anaynayak/6271234 to your computer and use it in GitHub Desktop.
Vagrantfile with proxy support, custom chef version installation using vagrant-omnibus, vagrant-cachier for caching packages, vagrant-butcher for managing vagrant chef client and node lifecycle, vagrant-berkshelf for pulling opscode cookbooks.
site :opscode
cookbook 'ntp'
[
{"vagrant-omnibus": "1.1.0"},
{"vagrant-cachier": "0.3.2"},
{"vagrant-butcher": "1.0.1"},
{"vagrant-berkshelf": "1.3.3"}
]
# -*- mode: ruby -*-
# vi: set ft=ruby :
# vagrant plugin install bindler
# vagrant plugin bundle
# vagrant up
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] # Use host resolver mechanism for DNS requests, see http://www.virtualbox.org/manual/ch09.html#nat-adv-dns
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] # Proxy guest dns requests to host, see http://www.virtualbox.org/manual/ch09.html#nat-adv-dns
end
config.vm.network :private_network, ip: "192.168.50.2"
config.vm.synced_folder ENV["PROJECT_HOME"] || ".", "/opt/app", :nfs => true # Use nfs shares for better performance, see https://coderwall.com/p/uaohzg
config.cache.auto_detect = true if config.cache.respond_to?(:cache) # Cache packages from apt/yum/rubygems/rvm etc, see https://github.com/fgrehm/vagrant-cachier
config.omnibus.chef_version = :latest if config.omnibus.respond_to?(:chef_version) # Use latest version of chef provisioner, see https://github.com/schisamo/vagrant-omnibus
config.ssh.forward_agent = true # Enable ssh forwarding
config.vm.define :application do |app_config|
proxy = ENV['APP_HTTP_PROXY']
if proxy
puts "Using proxy #{proxy}"
app_config.vm.provision :shell, :inline => "cat <<EOF | sudo tee /etc/profile.d/proxy.sh
export HTTP_PROXY=http://#{proxy}/
export HTTPS_PROXY=$http_proxy
export NO_PROXY=localhost,127.0.0.1
EOF" # Setup proxy.sh bash profile.d script so that it is automatically set.
end
app_config.vm.provision :chef_client do |chef|
chef.log_level = :debug
chef.chef_server_url = ENV['CHEF_SERVER_URL']
chef.validation_key_path = ENV['VALIDATION_KEY_PATH'] || 'validation.pem'
chef.environment = ENV['VAGRANT_ENVIRONMENT'] || '_default'
chef.node_name = "#{ENV['USER']}_vagrant" # Enforce vagrant chef client naming convention so that they can be easily filtered/identified.
chef.run_list = (ENV['run_list'] || 'recipe[ntp]').split(',')
chef.https_proxy = "http://#{proxy}/" if proxy # Use http proxy for chef provisioning, used in remote_file etc
chef.http_proxy = "http://#{proxy}/" if proxy # Use http(s) proxy for chef provisioning
end if ENV['CHEF_SERVER_URL']
app_config.vm.provision :chef_solo do |chef|
chef.log_level = :debug
chef.run_list = (ENV['run_list'] || 'recipe[ntp]').split(',')
chef.https_proxy = "http://#{proxy}/" if proxy # Use http proxy for chef provisioning, used in remote_file etc
chef.http_proxy = "http://#{proxy}/" if proxy # Use http(s) proxy for chef provisioning
end unless ENV['CHEF_SERVER_URL']
app_config.vm.network :forwarded_port, guest: 80, host: 8080
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment