Skip to content

Instantly share code, notes, and snippets.

@bennylope
Created February 27, 2013 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennylope/5050811 to your computer and use it in GitHub Desktop.
Save bennylope/5050811 to your computer and use it in GitHub Desktop.
Vagrant file setup (basic)

File structure

  • Vagrantfile - primary configuration
  • vagrantconfig.yaml - default configuration
  • vagrantconfig_local.yaml - local configuration, this file never gets checked into source control

Setup

The primary Vagrantfile is set up to use Ubuntu 12.04 LTS (Precise) and Puppet configuration has been commented out.

The (optional) vagrantconfig_local.yaml file can be used in this case to mount additional directories.

# Default config for Vagrant
# Don't change this; use vagrantconfig_local.yaml to override these
# settings instead.
nfs: false
nfs: true
mounts:
- name: "code"
virtual: "/var/code"
host: "~/Code"
# Gleefully borrowed from playdoh
require "yaml"
# Load up our vagrant config files -- vagrantconfig.yaml first
_config = YAML.load(File.open(File.join(File.dirname(__FILE__),
"vagrantconfig.yaml"), File::RDONLY).read)
# Local-specific/not-git-managed config -- vagrantconfig_local.yaml
begin
_config.merge!(YAML.load(File.open(File.join(File.dirname(__FILE__),
"vagrantconfig_local.yaml"), File::RDONLY).read))
rescue Errno::ENOENT # No vagrantconfig_local.yaml found -- that's OK; just
# use the defaults.
end
CONF = _config
MOUNT_POINT = '/var/apps/myapp/source'
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.forward_port 80, 8080, :auto => true # Nginx
config.vm.forward_port 8000, 8888, :auto => true # Django dev server
config.vm.forward_port 5000, 5555, :auto => true # Foreman/Honcho port
config.vm.forward_port 5432, 5480, :auto => true # PostgreSQL
config.vm.forward_port 22, 2222, :auto => true
# Increase vagrant's patience during hang-y CentOS bootup
# see: https://github.com/jedi4ever/veewee/issues/14
config.ssh.max_tries = 50
config.ssh.timeout = 300
if CONF['nfs'] == false or RUBY_PLATFORM =~ /mswin(32|64)/
nfs = false
end
config.vm.share_folder("app_root", MOUNT_POINT, ".", :nfs => nfs)
if CONF.has_key?("mounts")
CONF['mounts'].each do |folder|
config.vm.share_folder(folder['name'], folder['virtual'], folder['host'], :nfs => true)
end
end
# Add to /etc/hosts: 33.33.33.24 dev.playdoh.org
config.vm.network :hostonly, "33.33.33.24"
# Presuming no provisioning to start with
#config.vm.provision :puppet do |puppet|
# puppet.manifests_path = "puppet/manifests"
# puppet.manifest_file = "dev.pp"
# puppet.module_path = "puppet/modules"
# options = ["--environment", "dev"]
#end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment