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