blob: d91a8228c4ee8e76856af1b3efa291bcc301c974 [file] [log] [blame]
Pawel Wieczorekb7f08112019-07-19 19:10:07 +02001# -*- mode: ruby -*-
2# -*- coding: utf-8 -*-
3
4host_ip = "192.168.121.1"
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +02005operator_key = "${HOME}/.ssh/onap-key"
6vagrant_user = "vagrant"
7vagrant_password = "vagrant"
Pawel Wieczorekb7f08112019-07-19 19:10:07 +02008
9vm_memory = 2 * 1024
10vm_cpus = 1
11vm_box = "generic/ubuntu1804"
12
13operation = { name: 'operator', hostname: 'operator', ip: '172.17.0.254' }
14cluster = [
15 { name: 'control', hostname: 'control', ip: '172.17.0.100' },
16 { name: 'worker', hostname: 'worker', ip: '172.17.0.101' }
17]
18
19all = cluster.dup << operation
20
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020021$deploy_key = <<-SCRIPT
22 KEY="$1"
23 USER="$2"
24 PASS="$PASSWORD"
25 IPS="$3"
26 for ip in $IPS; do
27 sshpass -p "$PASS" ssh-copy-id -o StrictHostKeyChecking=no -i "$KEY" "${USER}@${ip}"
28 done
29SCRIPT
30
Pawel Wieczorek34e59322019-07-26 13:29:50 +020031$link_dotfiles = <<-SCRIPT
32 for rc in /vagrant/dot_*; do
33 ln -sf "$rc" "${HOME}/.${rc##*dot_}"
34 done
35SCRIPT
36
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020037Vagrant.configure('2') do |config|
38 all.each do |machine|
39 config.vm.define machine[:name] do |config|
40 config.vm.box = vm_box
41 config.vm.hostname = machine[:hostname]
42
43 config.vm.provider :virtualbox do |v|
44 v.name = machine[:name]
45 v.memory = vm_memory
46 v.cpus = vm_cpus
47 end
48
49 config.vm.provider :libvirt do |v|
50 v.memory = vm_memory
51 v.cpus = vm_cpus
52 end
53
54 config.vm.network :private_network, ip: machine[:ip]
55 config.vm.provision :shell, inline: <<-SHELL
56 rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
57 echo nameserver #{host_ip} | tee /etc/resolv.conf
58 SHELL
59
60 if machine[:name] == 'control'
61 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-controlnode.sh"
Pawel Wieczorek07adef32019-07-23 15:02:00 +020062 config.vm.provision :shell, inline: "usermod -aG docker vagrant" # script above adds "ubuntu" user only
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020063 end
64
65 if machine[:name] == 'worker'
66 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-workernode.sh"
Pawel Wieczorek07adef32019-07-23 15:02:00 +020067 config.vm.provision :shell, inline: "usermod -aG docker vagrant" # script above adds "ubuntu" user only
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020068 end
69
70 if machine[:name] == 'operator'
Pawel Wieczorek34e59322019-07-26 13:29:50 +020071 config.vm.synced_folder "../../tools/config", "/vagrant", type: "rsync"
72
73 config.vm.provision :shell, run: "always", inline: $link_dotfiles
74 config.vm.provision :shell, run: "always", privileged: false, inline: $link_dotfiles
75
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020076 config.vm.provision :shell, path: "../../tools/dublin/get_rke.sh"
77
78 config.vm.provision :shell, inline: <<-SHELL
79 apt-get update
80 apt-get install sshpass
81 SHELL
82 config.vm.provision :shell, privileged: false, inline: <<-SHELL
83 ssh-keygen -q -b 4096 -t rsa -f #{operator_key} -N ""
84 SHELL
85
86 ips = ""
87 cluster.each { |node| ips << node[:ip] << " " }
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020088 config.vm.provision :shell do |s|
89 s.privileged = false
90 s.inline = $deploy_key
91 s.args = [operator_key, vagrant_user, ips]
92 s.env = {'PASSWORD': vagrant_password}
93 end
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020094 end
95 end
96 end
97end