summaryrefslogtreecommitdiffstats
path: root/roles/ands_vagrant_vm/templates/Vagrantfile.j2
blob: 54128d40c94c4b3be8e4d86cd9445c8a6c9cb1cb (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
# -*- mode: ruby -*-
# vi: set ft=ruby :
{% set net = ands_openshift_network | ipaddr('network') | ipaddr(0) | regex_replace('\.\d+$', '')  %}
{% set storage_net = ands_storage_network | ipaddr('network') | ipaddr(0) | regex_replace('\.\d+$', '') %}
{% set netid = (  net | regex_replace('^.*\.', '') ) %}
{% set storage_netid = (  storage_net | regex_replace('^.*\.', '') ) %}
{% set macid = ( (netid | length) > 2 ) | ternary(netid, "0" ~ netid) %}

Vagrant.configure("2") do |config|
  (1..{{ vagrant_hosts }}).each do |i|
    config.vm.define "{{ vagrant_hostname_template }}#{i}" do |node|
        node.vm.network "public_network", bridge: "br0", mac: "080027{{ macid  }}02#{i}", ip: "{{ net }}.#{i}"
        node.vm.network "private_network",  mac: "080027{{ macid }}12#{i}", ip: "{{ storage_net }}.#{i}", name: "vboxnet0"
        node.vm.box = "centos/7"
        node.vm.hostname = "{{ vagrant_hostname_template }}#{i}.ipe.kit.edu"
#	node.vm.synced_folder "../data", "/root/data"

# Configuring DHCP in 'vm.network' causes 2 DHCP clients (dhclinet & nm) running in parallel and getting 2 IPs.
        node.vm.provision "shell", run: "always", inline: "( ip addr show | grep -v 141.52.64.15 | grep -v 141.52.64.17 | grep -v 141.52.64.28 | grep 141.52 ) || dhclient -cf /var/lib/NetworkManager/dhclient-eth0.conf eth1"
        node.vm.provision "shell", run: "always", inline: "( ip addr show | grep {{ netid }}.#{i} ) || ip addr add 192.168.{{ netid }}.#{i}/24 dev eth1"
        node.vm.provision "shell", run: "always", inline: "( ip addr show | grep {{ storage_netid }}.#{i} ) || ifcfg eth2 192.168.{{ storage_netid }}.#{i}"
        node.vm.provision "shell", run: "always", inline: "chmod +r /etc/sysconfig/network-scripts/ifcfg-eth*"
        node.vm.provision "shell", run: "always", inline: "chcon --reference /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth*"
        
        node.vm.provision "shell" do |s|
            ssh_pub_key = File.readlines("authorized_keys").first.strip
            s.inline = <<-SHELL
                mkdir -p /root/.ssh/
                echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
            SHELL
        end

        node.vm.provider "virtualbox" do |vb|
            vb.memory = "{{ 1024 * (vagrant_mem_size | int) }}"
            vb.cpus = {{ vagrant_cpu_cores }}
            #vb.gui = true
            vb.customize [
                "modifyvm", :id,
#               "--ostype", "Linux_64",
                "--audio", "none",
            ]
            vb.customize [
        	'createhd', '--filename', "../disks/#{i}", '--format', 'VDI', '--size', {{ 1024 * (vagrant_disk_size | int) }}
            ]
            vb.customize [
        	'storageattach', :id, '--storagectl', 'IDE Controller', '--port', 1, '--device', 0,'--type', 'hdd', '--medium', "../disks/#{i}.vdi"
            ]
        end
    end
  end
end