blob: 224cd9a1188cce7149b5c850e62e5ad6145d080c [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"
Pawel Wieczorek435200f2019-07-26 14:14:19 +020029 echo "Adding ${USER} to 'docker' group"
Pawel Wieczorek5ee92062019-07-26 13:58:02 +020030 usermod -aG docker "$USER"
31SCRIPT
32
Pawel Wieczorek6b1f78b2019-07-26 14:04:39 +020033$install_sshpass = <<-SCRIPT
34 apt-get update
Pawel Wieczorek435200f2019-07-26 14:14:19 +020035 echo "Installing 'sshpass'"
Pawel Wieczorek6b1f78b2019-07-26 14:04:39 +020036 apt-get install sshpass
37SCRIPT
38
39$generate_key = <<-SCRIPT
40 KEY_FILE="$1"
Pawel Wieczorek435200f2019-07-26 14:14:19 +020041 echo "Generating SSH key (${KEY_FILE})"
Pawel Wieczorek6b1f78b2019-07-26 14:04:39 +020042 ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N ""
43SCRIPT
44
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020045$deploy_key = <<-SCRIPT
46 KEY="$1"
47 USER="$2"
48 PASS="$PASSWORD"
49 IPS="$3"
Pawel Wieczorek435200f2019-07-26 14:14:19 +020050 echo "Deploying ${KEY} for ${USER}"
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020051 for ip in $IPS; do
Pawel Wieczorek435200f2019-07-26 14:14:19 +020052 echo "on ${ip}"
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +020053 sshpass -p "$PASS" ssh-copy-id -o StrictHostKeyChecking=no -i "$KEY" "${USER}@${ip}"
54 done
55SCRIPT
56
Pawel Wieczorek34e59322019-07-26 13:29:50 +020057$link_dotfiles = <<-SCRIPT
58 for rc in /vagrant/dot_*; do
Pawel Wieczorek435200f2019-07-26 14:14:19 +020059 src="$rc"
60 dst="${HOME}/.${rc##*dot_}"
61 echo "Symlinking ${src} to ${dst}"
62 ln -sf "$src" "$dst"
Pawel Wieczorek34e59322019-07-26 13:29:50 +020063 done
64SCRIPT
65
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020066Vagrant.configure('2') do |config|
67 all.each do |machine|
68 config.vm.define machine[:name] do |config|
69 config.vm.box = vm_box
70 config.vm.hostname = machine[:hostname]
71
72 config.vm.provider :virtualbox do |v|
73 v.name = machine[:name]
74 v.memory = vm_memory
75 v.cpus = vm_cpus
76 end
77
78 config.vm.provider :libvirt do |v|
79 v.memory = vm_memory
80 v.cpus = vm_cpus
81 end
82
83 config.vm.network :private_network, ip: machine[:ip]
Pawel Wieczorek63640ac2019-07-26 14:22:03 +020084 config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020085
86 if machine[:name] == 'control'
Pawel Wieczorek63640ac2019-07-26 14:22:03 +020087 config.vm.provision "customize_control", type: :shell, path: "../../tools/dublin/imported/openstack-k8s-controlnode.sh"
88 config.vm.provision "fix_groups_control", type: :shell, inline: $add_to_docker_group, args: vagrant_user
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020089 end
90
91 if machine[:name] == 'worker'
Pawel Wieczorek63640ac2019-07-26 14:22:03 +020092 config.vm.provision "customize_worker", type: :shell, path: "../../tools/dublin/imported/openstack-k8s-workernode.sh"
93 config.vm.provision "fix_group_worker", type: :shell, inline: $add_to_docker_group, args: vagrant_user
Pawel Wieczorekb7f08112019-07-19 19:10:07 +020094 end
95
96 if machine[:name] == 'operator'
Pawel Wieczorek34e59322019-07-26 13:29:50 +020097 config.vm.synced_folder "../../tools/config", "/vagrant", type: "rsync"
98
Pawel Wieczorek63640ac2019-07-26 14:22:03 +020099 config.vm.provision "link_dotfiles_root", type: :shell, run: "always", inline: $link_dotfiles
100 config.vm.provision "link_dotfiles_user", type: :shell, run: "always", privileged: false, inline: $link_dotfiles
Pawel Wieczorek34e59322019-07-26 13:29:50 +0200101
Pawel Wieczorek63640ac2019-07-26 14:22:03 +0200102 config.vm.provision "get_rke", type: :shell, path: "../../tools/dublin/get_rke.sh"
Pawel Wieczorekb7f08112019-07-19 19:10:07 +0200103
Pawel Wieczorek63640ac2019-07-26 14:22:03 +0200104 config.vm.provision "install_sshpass", type: :shell, inline: $install_sshpass
105 config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: operator_key
Pawel Wieczorekb7f08112019-07-19 19:10:07 +0200106
107 ips = ""
108 cluster.each { |node| ips << node[:ip] << " " }
Pawel Wieczorek63640ac2019-07-26 14:22:03 +0200109 config.vm.provision "deploy_key", type: :shell do |s|
Pawel Wieczorek9cf6f592019-07-26 13:40:23 +0200110 s.privileged = false
111 s.inline = $deploy_key
112 s.args = [operator_key, vagrant_user, ips]
113 s.env = {'PASSWORD': vagrant_password}
114 end
Pawel Wieczorekb7f08112019-07-19 19:10:07 +0200115 end
116 end
117 end
118end