blob: 36f433f18de0c74e5ecdb898cfd5a68e6be72829 [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 Wieczorek5ee92062019-07-26 13:58:02 +020021$add_to_docker_group = <<-SCRIPT
22 USER="$1"
23 usermod -aG docker "$USER"
24SCRIPT
25
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020026$deploy_key = <<-SCRIPT
27 KEY="$1"
28 USER="$2"
29 PASS="$PASSWORD"
30 IPS="$3"
31 for ip in $IPS; do
32 sshpass -p "$PASS" ssh-copy-id -o StrictHostKeyChecking=no -i "$KEY" "${USER}@${ip}"
33 done
34SCRIPT
35
Pawel Wieczorek34e59322019-07-26 13:29:50 +020036$link_dotfiles = <<-SCRIPT
37 for rc in /vagrant/dot_*; do
38 ln -sf "$rc" "${HOME}/.${rc##*dot_}"
39 done
40SCRIPT
41
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020042Vagrant.configure('2') do |config|
43 all.each do |machine|
44 config.vm.define machine[:name] do |config|
45 config.vm.box = vm_box
46 config.vm.hostname = machine[:hostname]
47
48 config.vm.provider :virtualbox do |v|
49 v.name = machine[:name]
50 v.memory = vm_memory
51 v.cpus = vm_cpus
52 end
53
54 config.vm.provider :libvirt do |v|
55 v.memory = vm_memory
56 v.cpus = vm_cpus
57 end
58
59 config.vm.network :private_network, ip: machine[:ip]
60 config.vm.provision :shell, inline: <<-SHELL
61 rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
62 echo nameserver #{host_ip} | tee /etc/resolv.conf
63 SHELL
64
65 if machine[:name] == 'control'
66 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-controlnode.sh"
Pawel Wieczorek5ee92062019-07-26 13:58:02 +020067 config.vm.provision :shell, inline: $add_to_docker_group, args: vagrant_user
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020068 end
69
70 if machine[:name] == 'worker'
71 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-workernode.sh"
Pawel Wieczorek5ee92062019-07-26 13:58:02 +020072 config.vm.provision :shell, inline: $add_to_docker_group, args: vagrant_user
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020073 end
74
75 if machine[:name] == 'operator'
Pawel Wieczorek34e59322019-07-26 13:29:50 +020076 config.vm.synced_folder "../../tools/config", "/vagrant", type: "rsync"
77
78 config.vm.provision :shell, run: "always", inline: $link_dotfiles
79 config.vm.provision :shell, run: "always", privileged: false, inline: $link_dotfiles
80
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020081 config.vm.provision :shell, path: "../../tools/dublin/get_rke.sh"
82
83 config.vm.provision :shell, inline: <<-SHELL
84 apt-get update
85 apt-get install sshpass
86 SHELL
87 config.vm.provision :shell, privileged: false, inline: <<-SHELL
88 ssh-keygen -q -b 4096 -t rsa -f #{operator_key} -N ""
89 SHELL
90
91 ips = ""
92 cluster.each { |node| ips << node[:ip] << " " }
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020093 config.vm.provision :shell do |s|
94 s.privileged = false
95 s.inline = $deploy_key
96 s.args = [operator_key, vagrant_user, ips]
97 s.env = {'PASSWORD': vagrant_password}
98 end
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020099 end
100 end
101 end
102end