blob: e7fe6b1ecb0477e70c0d9f96f191bc4d178553bd [file] [log] [blame]
Pawel Wieczorekb7f08112019-07-19 19:10:07 +02001# -*- mode: ruby -*-
2# -*- coding: utf-8 -*-
3
4host_ip = "192.168.121.1"
5operator_key = "~/.ssh/onap-key"
6
7vm_memory = 2 * 1024
8vm_cpus = 1
9vm_box = "generic/ubuntu1804"
10
11operation = { name: 'operator', hostname: 'operator', ip: '172.17.0.254' }
12cluster = [
13 { name: 'control', hostname: 'control', ip: '172.17.0.100' },
14 { name: 'worker', hostname: 'worker', ip: '172.17.0.101' }
15]
16
17all = cluster.dup << operation
18
Pawel Wieczorek34e59322019-07-26 13:29:50 +020019$link_dotfiles = <<-SCRIPT
20 for rc in /vagrant/dot_*; do
21 ln -sf "$rc" "${HOME}/.${rc##*dot_}"
22 done
23SCRIPT
24
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020025Vagrant.configure('2') do |config|
26 all.each do |machine|
27 config.vm.define machine[:name] do |config|
28 config.vm.box = vm_box
29 config.vm.hostname = machine[:hostname]
30
31 config.vm.provider :virtualbox do |v|
32 v.name = machine[:name]
33 v.memory = vm_memory
34 v.cpus = vm_cpus
35 end
36
37 config.vm.provider :libvirt do |v|
38 v.memory = vm_memory
39 v.cpus = vm_cpus
40 end
41
42 config.vm.network :private_network, ip: machine[:ip]
43 config.vm.provision :shell, inline: <<-SHELL
44 rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
45 echo nameserver #{host_ip} | tee /etc/resolv.conf
46 SHELL
47
48 if machine[:name] == 'control'
49 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-controlnode.sh"
Pawel Wieczorek07adef32019-07-23 15:02:00 +020050 config.vm.provision :shell, inline: "usermod -aG docker vagrant" # script above adds "ubuntu" user only
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020051 end
52
53 if machine[:name] == 'worker'
54 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-workernode.sh"
Pawel Wieczorek07adef32019-07-23 15:02:00 +020055 config.vm.provision :shell, inline: "usermod -aG docker vagrant" # script above adds "ubuntu" user only
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020056 end
57
58 if machine[:name] == 'operator'
Pawel Wieczorek34e59322019-07-26 13:29:50 +020059 config.vm.synced_folder "../../tools/config", "/vagrant", type: "rsync"
60
61 config.vm.provision :shell, run: "always", inline: $link_dotfiles
62 config.vm.provision :shell, run: "always", privileged: false, inline: $link_dotfiles
63
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020064 config.vm.provision :shell, path: "../../tools/dublin/get_rke.sh"
65
66 config.vm.provision :shell, inline: <<-SHELL
67 apt-get update
68 apt-get install sshpass
69 SHELL
70 config.vm.provision :shell, privileged: false, inline: <<-SHELL
71 ssh-keygen -q -b 4096 -t rsa -f #{operator_key} -N ""
72 SHELL
73
74 ips = ""
75 cluster.each { |node| ips << node[:ip] << " " }
76 config.vm.provision :shell, privileged: false, inline: <<-SHELL
77 for ip in #{ips}; do
78 sshpass -p vagrant ssh-copy-id -o StrictHostKeyChecking=no -i #{operator_key} "$ip"
79 done
80 SHELL
81 end
82 end
83 end
84end