blob: 9e92580fa229a47b60dcd50a1f115960883bf427 [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 Wieczorek6b1f78b2019-07-26 14:04:39 +020021$replace_dns = <<-SCRIPT
22 HOST_IP="$1"
23 rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
24 echo nameserver "$HOST_IP" | tee /etc/resolv.conf
25SCRIPT
26
Pawel Wieczorek5ee92062019-07-26 13:58:02 +020027$add_to_docker_group = <<-SCRIPT
28 USER="$1"
29 usermod -aG docker "$USER"
30SCRIPT
31
Pawel Wieczorek6b1f78b2019-07-26 14:04:39 +020032$install_sshpass = <<-SCRIPT
33 apt-get update
34 apt-get install sshpass
35SCRIPT
36
37$generate_key = <<-SCRIPT
38 KEY_FILE="$1"
39 ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N ""
40SCRIPT
41
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020042$deploy_key = <<-SCRIPT
43 KEY="$1"
44 USER="$2"
45 PASS="$PASSWORD"
46 IPS="$3"
47 for ip in $IPS; do
48 sshpass -p "$PASS" ssh-copy-id -o StrictHostKeyChecking=no -i "$KEY" "${USER}@${ip}"
49 done
50SCRIPT
51
Pawel Wieczorek34e59322019-07-26 13:29:50 +020052$link_dotfiles = <<-SCRIPT
53 for rc in /vagrant/dot_*; do
54 ln -sf "$rc" "${HOME}/.${rc##*dot_}"
55 done
56SCRIPT
57
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020058Vagrant.configure('2') do |config|
59 all.each do |machine|
60 config.vm.define machine[:name] do |config|
61 config.vm.box = vm_box
62 config.vm.hostname = machine[:hostname]
63
64 config.vm.provider :virtualbox do |v|
65 v.name = machine[:name]
66 v.memory = vm_memory
67 v.cpus = vm_cpus
68 end
69
70 config.vm.provider :libvirt do |v|
71 v.memory = vm_memory
72 v.cpus = vm_cpus
73 end
74
75 config.vm.network :private_network, ip: machine[:ip]
Pawel Wieczorek6b1f78b2019-07-26 14:04:39 +020076 config.vm.provision :shell, run: "always", inline: $replace_dns, args: host_ip
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020077
78 if machine[:name] == 'control'
79 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-controlnode.sh"
Pawel Wieczorek5ee92062019-07-26 13:58:02 +020080 config.vm.provision :shell, inline: $add_to_docker_group, args: vagrant_user
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020081 end
82
83 if machine[:name] == 'worker'
84 config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-workernode.sh"
Pawel Wieczorek5ee92062019-07-26 13:58:02 +020085 config.vm.provision :shell, inline: $add_to_docker_group, args: vagrant_user
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020086 end
87
88 if machine[:name] == 'operator'
Pawel Wieczorek34e59322019-07-26 13:29:50 +020089 config.vm.synced_folder "../../tools/config", "/vagrant", type: "rsync"
90
91 config.vm.provision :shell, run: "always", inline: $link_dotfiles
92 config.vm.provision :shell, run: "always", privileged: false, inline: $link_dotfiles
93
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020094 config.vm.provision :shell, path: "../../tools/dublin/get_rke.sh"
95
Pawel Wieczorek6b1f78b2019-07-26 14:04:39 +020096 config.vm.provision :shell, inline: $install_sshpass
97 config.vm.provision :shell, privileged: false, inline: $generate_key, args: operator_key
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020098
99 ips = ""
100 cluster.each { |node| ips << node[:ip] << " " }
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +0200101 config.vm.provision :shell do |s|
102 s.privileged = false
103 s.inline = $deploy_key
104 s.args = [operator_key, vagrant_user, ips]
105 s.env = {'PASSWORD': vagrant_password}
106 end
Pawel Wieczorekb7f08112019-07-19 19:10:07 +0200107 end
108 end
109 end
110end