Created
September 26, 2014 21:22
-
-
Save nathanielks/f6cf4ceac96a5c47e49e to your computer and use it in GitHub Desktop.
Improved bedrock-ansible Vagrantfile
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 : | |
Vagrant.require_version '>= 1.5.1' | |
Vagrant.configure('2') do |config| | |
config.vm.box = 'roots/bedrock' | |
# Required for NFS to work, pick any local IP | |
config.vm.network :private_network, ip: '192.168.50.5' | |
config.vm.hostname = 'example.dev' | |
if !Vagrant.has_plugin? 'vagrant-hostsupdater' | |
puts 'vagrant-hostsupdater missing, please install the plugin:' | |
puts 'vagrant plugin install vagrant-hostsupdater' | |
else | |
# If you have multiple sites/hosts on a single VM | |
# uncomment and add them here | |
#config.hostsupdater.aliases = %w(site2.dev) | |
end | |
# adjust paths relative to Vagrantfile | |
# Use NFS for shared folders for better performance | |
config.vm.synced_folder '../example.dev', '/srv/www/example.dev/current', nfs: true | |
config.vm.provision :ansible do |ansible| | |
# adjust paths relative to Vagrantfile | |
ansible.playbook = './site.yml' | |
ansible.groups = { | |
'web' => ['default'], | |
'development' => ['default'] | |
} | |
ansible.extra_vars = { | |
ansible_ssh_user: 'vagrant', | |
user: 'vagrant' | |
} | |
ansible.sudo = true | |
end | |
config.vm.provider "virtualbox" do |vb| | |
host = RbConfig::CONFIG['host_os'] | |
# Give VM 1/4 system memory & access to all cpu cores on the host | |
if host =~ /darwin/ | |
cpus = `sysctl -n hw.ncpu`.to_i | |
# sysctl returns Bytes and we need to convert to MB | |
mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4 | |
elsif host =~ /linux/ | |
cpus = `nproc`.to_i | |
# meminfo shows KB and we need to convert to MB | |
mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4 | |
else # sorry Windows folks, I can't help you | |
cpus = 2 | |
mem = 1024 | |
end | |
vb.customize ["modifyvm", :id, "--memory", mem] | |
vb.customize ["modifyvm", :id, "--cpus", cpus] | |
# Fix for slow external network connections | |
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] | |
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment