diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2017-04-01 04:53:28 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2017-04-01 04:53:28 +0200 |
commit | e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86 (patch) | |
tree | 444778102e4f73b83ef9462235b7f614b004b264 /roles/ands_vagrant_vm/templates | |
download | ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.tar.gz ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.tar.bz2 ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.tar.xz ands-e7ed329bd81c2273c03e94c93c9ce9c1d01cdc86.zip |
Initial import
Diffstat (limited to 'roles/ands_vagrant_vm/templates')
-rw-r--r-- | roles/ands_vagrant_vm/templates/Vagrantfile.j2 | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/roles/ands_vagrant_vm/templates/Vagrantfile.j2 b/roles/ands_vagrant_vm/templates/Vagrantfile.j2 new file mode 100644 index 0000000..54128d4 --- /dev/null +++ b/roles/ands_vagrant_vm/templates/Vagrantfile.j2 @@ -0,0 +1,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 |