| 1 |
# -*- mode: ruby -*- |
| 2 |
# vi: set ft=ruby : |
| 3 |
|
| 4 |
Vagrant.configure("2") do |config| |
| 5 |
config.vm.define "vagrant-testVM" do |testvm| |
| 6 |
testvm.vm.box = "gluster-dev-fedora" |
| 7 |
testvm.vm.box_url = "http://download.gluster.org/pub/gluster/glusterfs/vagrant/gluster-dev-fedora/boxes/gluster-dev-fedora.json" |
| 8 |
testvm.vm.hostname = "vagrant-testVM" |
| 9 |
#testvm.ssh.insert_key = false |
| 10 |
testvm.vm.synced_folder ".", "/vagrant", disabled: true |
| 11 |
|
| 12 |
host = RbConfig::CONFIG['host_os'] |
| 13 |
# Give VM 1/4 system memory & access to all cpu cores on the host |
| 14 |
if host =~ /darwin/ |
| 15 |
cpus = `sysctl -n hw.ncpu`.to_i |
| 16 |
# sysctl returns Bytes and we need to convert to MB |
| 17 |
mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4 |
| 18 |
elsif host =~ /linux/ |
| 19 |
cpus = `nproc`.to_i |
| 20 |
# meminfo shows KB and we need to convert to MB |
| 21 |
mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4 |
| 22 |
else # sorry Windows folks, I can't help you |
| 23 |
cpus = 2 |
| 24 |
mem = 1024 |
| 25 |
end |
| 26 |
|
| 27 |
# Define basic config for VM, memory, cpu, storage pool |
| 28 |
testvm.vm.provider "libvirt" do |lv| |
| 29 |
lv.storage_pool_name = "default" |
| 30 |
lv.memory = mem |
| 31 |
lv.cpus = cpus |
| 32 |
|
| 33 |
|
| 34 |
# We need a brick partition, lets have a 5G disk for that. |
| 35 |
# If you need more bricks, just add more letters to the |
| 36 |
# string below. |
| 37 |
"b".split("").each do |i| |
| 38 |
lv.storage :file, |
| 39 |
#:path => "", |
| 40 |
#:allow_existing => "", |
| 41 |
:device => "vd#{i}", |
| 42 |
:size => "5G", |
| 43 |
:type => "qcow2", |
| 44 |
:bus => "virtio", |
| 45 |
:cache => "default" |
| 46 |
end |
| 47 |
end |
| 48 |
|
| 49 |
# Let's provision |
| 50 |
testvm.vm.provision "ansible", run: "always" do |setup| |
| 51 |
setup.verbose = "v" |
| 52 |
setup.playbook = "setup.yml" |
| 53 |
end |
| 54 |
|
| 55 |
end |
| 56 |
end |