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