Created
October 22, 2018 16:06
-
-
Save koaps/e844742b9741e5119e9c222cc137bc7c to your computer and use it in GitHub Desktop.
Vagrant ZFS example
This file contains 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
--- | |
- vars: | |
boot: network | |
box: ubuntu1604 | |
box_url: packer/box/ubuntu1604-0.1.1.box | |
nested: false | |
ssh_name: ubuntu | |
ssh_privkey: ~/.ssh/id_rsa | |
- name: dev-ceph01 | |
disks: | |
- 60G | |
- 100G | |
- 100G | |
ram: 4096 | |
vcpu: 2 | |
macs: | |
- 00:00:00:01:0a:01 | |
- 00:00:00:01:0a:02 | |
- name: dev-compute01 | |
disks: | |
- 160G | |
ram: 4096 | |
vcpu: 4 | |
macs: | |
- 00:00:00:01:0a:03 | |
- 00:00:00:01:0a:04 | |
- name: dev-compute02 | |
disks: | |
- 160G | |
ram: 4096 | |
vcpu: 4 | |
macs: | |
- 00:00:00:01:0a:05 | |
- 00:00:00:01:0a:06 | |
- name: dev-lxc01 | |
disks: | |
- 160G | |
ram: 32768 | |
vcpu: 6 | |
macs: | |
- 00:00:00:01:0a:07 | |
- 00:00:00:01:0a:08 |
This file contains 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 : | |
# Specify minimum Vagrant version and Vagrant API version | |
Vagrant.require_version '>= 1.9.1' | |
VAGRANTFILE_API_VERSION = '2' | |
# Require 'yaml' module | |
require 'yaml' | |
# Read YAML file with VM details (box, CPU, and RAM) | |
nodes = YAML.load_file(File.join(File.dirname(__FILE__), 'nodes.yml')) | |
vars = nodes.shift | |
# Create and configure the VMs | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.ssh.forward_agent = true | |
config.ssh.insert_key = false | |
config.ssh.private_key_path = vars['ssh_privkey'] | |
config.ssh.username = vars['ssh_name'] | |
nodes.each do |node| | |
config.vm.define node['name'] do |srv| | |
srv.trigger.before :up, :force => true do | |
count = 0 | |
node['disks'].each do |disk| | |
run "virsh vol-create-as zfspool #{node['name']}_#{count} #{disk}" | |
count += 1 | |
end | |
end | |
srv.trigger.after :destroy do | |
count = 0 | |
node['disks'].each do |disk| | |
run "virsh vol-delete #{node['name']}_#{count} --pool zfspool" | |
count += 1 | |
end | |
end | |
srv.vm.hostname = node['name'] | |
srv.vm.network :private_network, | |
:libvirt__network_name => 'br0_net', | |
:mac => node['macs'][0], | |
:model_type => 'virtio' | |
srv.vm.network :private_network, | |
:libvirt__network_name => 'br0_net', | |
:mac => node['macs'][1], | |
:model_type => 'virtio' | |
# Configure default synced folder (disable by default) | |
if vars['sync_disabled'] != nil | |
srv.vm.synced_folder '.', '/vagrant', disabled: vars['sync_disabled'] | |
else | |
srv.vm.synced_folder '.', '/vagrant', disabled: true | |
end #if machine['sync_disabled'] | |
srv.vm.provider :libvirt do |domain| | |
domain.boot vars['boot'] | |
domain.cpus = node['vcpu'] | |
domain.default_prefix = "" | |
domain.driver = "kvm" | |
domain.host = 'localhost' | |
domain.machine_arch = "x86_64" | |
domain.memory = node['ram'] | |
domain.mgmt_attach = false | |
domain.nested = vars['nested'] | |
count = 0 | |
node['disks'].each do |disk| | |
domain.storage :file, :size => node['disks'][count], :path => "#{node['name']}_#{count}", :allow_existing => true, :type => 'raw' | |
count += 1 | |
end | |
domain.storage_pool_name = "zfspool" | |
domain.uri = 'qemu:///system' | |
end | |
end # end srv | |
end # end node | |
end # end config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment