summaryrefslogtreecommitdiffstats
path: root/vagrant/Vagrantfile
blob: cca772f9b9c190facb61e9651c8b4f306c9024ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- mode: ruby -*-
# vi: set ft=ruby :
#

NODES = 2
DISKS = 2
NODE_RAM = 1024
NODE_CPUS = 2
PRIVATE_NETWORK_BASE = "192.168.122"
PUBLIC_NETWORK_BASE = "192.168.123"
#LIBVIRT_STORAGE_POOL = "data"

SETUP_IP = "#{PRIVATE_NETWORK_BASE}.200"
CLIENT_IP = "#{PUBLIC_NETWORK_BASE}.5"

Vagrant.configure("2") do |config|
    config.ssh.insert_key = false
    config.vm.provider :libvirt do |v,override|
        override.vm.box = "centos/7"
        override.vm.synced_folder '.', '/vagrant', disabled: true

        # We can not use qemu_use_session universally.
        # - On Fedora 31, it is required for me to start.
        # - But on centos7, it must not be set.
        # The best workarount I found is to put this setting into
        # your ~/.vagrant.d/Vagrantfile like so:
        # ```
        # Vagrant.configure("2") do |config|
        #   config.vm.provider :libvirt do |libvirt|
        #     libvirt.qemu_use_session = false
        #   end
        # end
        # ```
        #v.qemu_use_session = false

        # change cpu mode to passthrough as workaround for problems in the ci,
        # refer to bugs:
        # https://bugzilla.redhat.com/show_bug.cgi?id=1467599
        # https://bugzilla.redhat.com/show_bug.cgi?id=1386223#c10
        # vagrant-libvirt/vagrant-libvirt#667
        # taken from:
        # https://github.com/heketi/heketi/pull/1008
        v.cpu_mode = 'host-passthrough'
    end

    (0..NODES-1).each do |i|
        config.vm.define "storage#{i}" do |storage|
            storage.vm.hostname = "storage#{i}"
            storage.vm.network :private_network, ip: "#{PRIVATE_NETWORK_BASE}.10#{i}"
            storage.vm.network :private_network, ip: "#{PUBLIC_NETWORK_BASE}.10#{i}"
            (0..DISKS-1).each do |d|
                storage.vm.provider :virtualbox do |vb|
                    vb.customize [ "createhd", "--filename", "disk-#{i}#{d}.vdi", "--size", 10*1024 ]
                    vb.customize [ "storageattach", :id, "--storagectl", "SATA Controller", "--port", 3+d, "--device", 0, "--type", "hdd", "--medium", "disk-#{i}#{d}.vdi" ]
                    vb.memory = NODE_RAM
                    vb.cpus = NODE_CPUS
                end

                driverletters = ('b'..'z').to_a
                storage.vm.provider :libvirt do  |lv|
                    if defined?(LIBVIRT_STORAGE_POOL)
                      lv.storage_pool_name = "#{LIBVIRT_STORAGE_POOL}"
                    end
                    lv.storage :file, :device => "vd#{driverletters[d]}", :path => "disk-#{i}#{d}.disk", :size => '10G'
                    lv.memory = NODE_RAM
                    lv.cpus = NODE_CPUS
                end
            end
        end
    end


    # Client vm:
    # This VM will connect to the cluster over the public ip addresses
    config.vm.define "client1" do |setup|
      setup.vm.hostname = "client1"
      setup.vm.network :private_network, ip: "#{CLIENT_IP}"
    end

    # setup vm:
    # We will runn all our setup playbooks from there.
    config.vm.define "setup" do |setup|
      setup.vm.hostname = "setup"
      setup.vm.network :private_network, ip: "#{SETUP_IP}"
      # Run a no-op playbook to create the inventory file.
      # Based on that, one can run ansible without vagrant.
      setup.vm.provision "no-op", type:'ansible' do |ansible|
        ansible.playbook = "no-op-playbook.yml"
        ansible.groups = {
          "admin" => [ "setup" ],
          "clients" => [ "client1" ],
          "cluster" => (0..NODES-1).map { |i| "storage#{i}" }
        }
      end
    end

end