Skip to content

Instantly share code, notes, and snippets.

@kwilczynski
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save kwilczynski/83f60bb7a4f106da62e4 to your computer and use it in GitHub Desktop.

Select an option

Save kwilczynski/83f60bb7a4f106da62e4 to your computer and use it in GitHub Desktop.
Vagrant with multiple storage attached
```
if Vagrant.has_plugin?('vagrant-hostmanager')
config.hostmanager.enabled = true
config.hostmanager.manage_host = false
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
end
```
Update sudoers:
```
Cmnd_Alias VAGRANT_HOSTS_UPDATE = /bin/cp /home/user/.vagrant.d/tmp/hosts.local /etc/hosts
%sudo ALL=(root) NOPASSWD: VAGRANT_HOSTS_UPDATE
```
Vagrant.configure('2') do |config|
config.ssh.forward_agent = true
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box
config.cache.auto_detect = true
end
if Vagrant.has_plugin?('vagrant-omnibus')
config.omnibus.chef_version = :latest
end
config.vm.define :ubuntu do |machine|
machine.vm.box = 'ubuntu-14.04-amd64'
machine.vm.hostname = 'ubuntu'
#machine.vm.network :private_network, ip: '192.168.100.10'
machine.vm.network 'forwarded_port', guest: 80, host: 8080
machine.vm.provider 'vmware_fusion' do |vmware|
vmware.vmx['memzise'] = '512'
vmware.vmx['numvcpus'] = '2'
vmware.vmx['logging'] = 'FALSE'
vmware.vmx['MemTrimRate'] = '0'
vmware.vmx['MemAllowAutoScaleDown'] = 'FALSE'
vmware.vmx['mainMem.backing'] = 'swap'
vmware.vmx['mainMem.useNamedFile'] = 'FALSE'
vmware.vmx['sched.mem.pshare.enable'] = 'FALSE'
vmware.vmx['snapshot.disabled'] = 'TRUE'
vmware.vmx['isolation.tools.unity.disable'] = 'TRUE'
vmware.vmx['prefvmx.useRecommendedLockedMemSize'] = 'TRUE'
vmware.vmx['prefvmx.minVmMemPct'] = '100'
end
end
config.vm.define :centos65 do |machine|
machine.vm.box = 'chef/centos-6.5'
machine.vm.hostname = 'centos65'
#machine.vm.network :private_network, ip: '192.168.200.10'
machine.vm.network 'forwarded_port', guest: 80, host: 8080
machine.vm.provider 'vmware_fusion' do |vmware|
vmware.vmx['memzise'] = '512'
vmware.vmx['numvcpus'] = '2'
vmware.vmx['logging'] = 'FALSE'
vmware.vmx['MemTrimRate'] = '0'
vmware.vmx['MemAllowAutoScaleDown'] = 'FALSE'
vmware.vmx['mainMem.backing'] = 'swap'
vmware.vmx['mainMem.useNamedFile'] = 'FALSE'
vmware.vmx['sched.mem.pshare.enable'] = 'FALSE'
vmware.vmx['snapshot.disabled'] = 'TRUE'
vmware.vmx['isolation.tools.unity.disable'] = 'TRUE'
vmware.vmx['prefvmx.useRecommendedLockedMemSize'] = 'TRUE'
vmware.vmx['prefvmx.minVmMemPct'] = '100'
end
end
end
config.vm.provider "vmware_fusion" do |v|
v.vmx["ethernet1.present"] = "TRUE"
v.vmx["ethernet1.connectionType"] = "hostonly"
v.vmx["ethernet1.addressType"] = "generated"
v.vmx["ethernet1.virtualDev"] = "e1000"
end
vmware.vmx["ethernet0.present"] = "TRUE"
vmware.vmx["ethernet0.connectionType"] = "nat"
vmware.vmx["ethernet1.generatedAddress"] = nil
vmware.vmx["ethernet1.addressType"] = "static"
vmware.vmx["ethernet1.present"] = "TRUE"
vmware.vmx["ethernet1.connectionType"] = "bridged"
vmware.vmx["ethernet1.address"] = "00:0C:29:DB:08:02"
v.vmx["ethernet1.present"] = "TRUE"
v.vmx["ethernet1.connectionType"] = "hostonly"
v.vmx["ethernet1.virtualDev"] = "e1000"
v.vmx["ethernet1.wakeOnPcktRcv"] = "FALSE"
v.vmx["ethernet1.addressType"] = "generated"
machine.vm.provider :virtualbox do |vb|
vb.name = 'ubuntu1404'
vb.customize ['modifyvm', :id,
# Disabled: '--ioapic', 'on',
'--chipset', 'ich9',
'--memory', '512',
'--cpus', '1',
'--pae', 'on',
'--cpuexecutioncap', '90',
'--rtcuseutc', 'on',
'--natdnshostresolver1', 'on',
'--natdnsproxy1', 'on',
'--groups', '/vagrant'
]
chef.custom_config_path = 'Vagrantfile.chef'
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /etc/exports
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_EXPORTS_REMOVE
%sudo ALL=(root) NOPASSWD: AGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY
Vagrant.configure('2') do |config|
config.ssh.forward_agent = true
# For vagrant-cashier plugin, see: http://fgrehm.viewdocs.io/vagrant-cachier
# config.cache.scope = :box
# config.cache.auto_detect = true
config.vm.define :centos65 do |machine|
machine.vm.box = 'chef/centos-6.5'
machine.vm.hostname = 'centos65'
# Tweak accordingly, if needed.
# machine.vm.network :private_network, ip: '172.16.1.10'
# machine.vm.network 'forwarded_port', guest: 80, host: 8080
machine.vm.provider :virtualbox do |vb|
# Uncomment to set specific Virtual Machine name in VirtualBox.
#vb.name = 'centos65'
vb.customize ['modifyvm', :id,
'--memory', '4096',
'--cpus', '2',
'--rtcuseutc', 'on',
'--natdnshostresolver1', 'on'
'--nictype1', 'virtio',
'--nictype2', 'virtio'
]
# Attach SATA AHCI controller, if needed.
vb.customize ['storagectl', :id,
'--name', 'SATA Controller',
'--add', 'sata'
]
vb.customize ['createhd',
'--filename', 'centos65-disk1.vdi',
'--size', 10*1024
]
vb.customize ['createhd',
'--filename', 'centos65-disk2.vdi',
'--size', 10*1024
]
vb.customize ['storageattach', :id,
'--storagectl', 'SATA Controller',
'--port', 1,
'--device', 0,
'--type', 'hdd',
'--medium', 'centos65-disk1.vdi']
vb.customize ['storageattach', :id,
'--storagectl', 'IDE Controller', # Alternatively: SATA Controller
'--port', 1,
'--device', 1,
'--type', 'hdd',
'--medium', 'centos65-disk2.vdi']
end
machine.vm.provision 'shell', inline: <<-EOS.gsub(/^\s+/,'')
disk=1
for l in b c d e ; do
[ -e /dev/sd${l}1 ] && continue ;
(echo o; echo n; echo p; echo 1; echo; echo; echo w) | sudo fdisk /dev/sd${l} > /dev/null 2>&1 || true
yes | sudo mkfs.ext4 -q /dev/sd${l}1 > /dev/null 2>&1 || true
sudo mkdir -p /mnt/#{machine.vm.hostname}-disk-${disk} > /dev/null 2>&1 || true
sudo mount /dev/sd${l}1 /mnt/#{machine.vm.hostname}-disk-${disk} > /dev/null 2>&1 || true
disk=$(( disk + 1 ))
done
EOS
end
end
def is_up?
ARGV[0] == 'up' || ARGV.include?('up')
end
def disk(name)
::File.join(Vagrant.user_data_path, name)
end
def disk_exists?(name)
::File.exists?(::File.join(Vagrant.user_data_path, name))
end
Vagrant.configure('2') do |config|
config.ssh.forward_agent = true
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box
config.cache.auto_detect = true
end
(1..5).each do |n|
name = "mapr-#{n}"
config.vm.define name.to_sym do |machine|
machine.vm.box = 'chef/centos-6.5'
machine.vm.hostname = name
machine.vm.network :private_network, ip: "172.16.1.1#{n}"
machine.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id,
'--chipset', 'ich9',
'--memory', '256',
'--cpus', '2',
'--rtcuseutc', 'on',
'--natdnshostresolver1', 'on'
]
if is_up? && ! disk_exists?("#{machine.vm.hostname}-disk1.vdi")
vb.customize ['storagectl', :id,
'--name', 'SATA Controller',
'--add', 'sata'
]
vb.customize ['createhd',
'--filename', disk("#{machine.vm.hostname}-disk1.vdi"),
'--size', 1*1024
]
vb.customize ['createhd',
'--filename', disk("#{machine.vm.hostname}-disk2.vdi"),
'--size', 1*1024
]
end
vb.customize ['storageattach', :id,
'--storagectl', 'SATA Controller',
'--port', 1,
'--device', 0,
'--type', 'hdd',
'--medium', disk("#{machine.vm.hostname}-disk1.vdi"),
]
vb.customize ['storageattach', :id,
'--storagectl', 'SATA Controller',
'--port', 2,
'--device', 0,
'--type', 'hdd',
'--medium', disk("#{machine.vm.hostname}-disk2.vdi"),
]
end
end
end
config.vm.provision 'shell', inline: <<-EOS.gsub(/^\s+/,'')
for l in b c d e f; do
[ -e /dev/sd${l}1 ] && continue ;
(echo o; echo n; echo p; echo 1; echo; echo; echo w) | \
sudo fdisk /dev/sd${l} > /dev/null 2>&1 || true
done
EOS
end
Chef::Config.ssl_verify_mode = :verify_peer
Vagrant.configure('2') do |config|
config.ssh.forward_agent = true
config.cache.scope = :box
config.cache.auto_detect = true
config.vm.define :ubuntu do |machine|
machine.vm.box = 'ubuntu-13.04-server-x86'
machine.vm.hostname = 'ubuntu'
machine.vm.network :private_network, ip: '192.168.100.10'
# Disabled: machine.vm.network 'private_network', type: 'dhcp'
machine.vm.network 'forwarded_port', guest: 80, host: 8080
machine.vm.synced_folder '.', '/vagrant', nfs: true
machine.vm.provider :virtualbox do |vb|
vb.name = 'ubuntu'
vb.customize ['modifyvm', :id,
# Disabled: '--ioapic', 'on',
'--chipset', 'ich9',
'--memory', '256',
'--cpus', '1',
'--pae', 'on',
'--cpuexecutioncap', '90',
'--rtcuseutc', 'on',
'--natdnshostresolver1', 'on',
'--groups', '/vagrant'
]
end
end
config.vm.define :centos65 do |machine|
machine.vm.box = 'chef/centos-6.5-i386'
machine.vm.hostname = 'centos65'
machine.vm.network :private_network, ip: '192.168.200.10'
# Disabled: machine.vm.network 'private_network', type: 'dhcp'
machine.vm.network 'forwarded_port', guest: 80, host: 8080
machine.vm.synced_folder '.', '/vagrant', nfs: true
machine.vm.provider :virtualbox do |vb|
vb.name = 'centos65'
vb.customize ['modifyvm', :id,
# Disabled: '--ioapic', 'on',
'--chipset', 'ich9',
'--memory', '256',
'--cpus', '1',
'--pae', 'on',
'--cpuexecutioncap', '90',
'--rtcuseutc', 'on',
'--natdnshostresolver1', 'on',
'--groups', '/vagrant'
]
end
end
end
@kwilczynski
Copy link
Author

Note that the sudoers file is for Debian et al.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment