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" |
Pawel Wieczorek | 9cf6f59 | 2019-07-26 13:40:23 +0200 | [diff] [blame] | 5 | operator_key = "${HOME}/.ssh/onap-key" |
| 6 | vagrant_user = "vagrant" |
| 7 | vagrant_password = "vagrant" |
Pawel Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 8 | |
| 9 | vm_memory = 2 * 1024 |
| 10 | vm_cpus = 1 |
| 11 | vm_box = "generic/ubuntu1804" |
| 12 | |
| 13 | operation = { name: 'operator', hostname: 'operator', ip: '172.17.0.254' } |
| 14 | cluster = [ |
| 15 | { name: 'control', hostname: 'control', ip: '172.17.0.100' }, |
| 16 | { name: 'worker', hostname: 'worker', ip: '172.17.0.101' } |
| 17 | ] |
| 18 | |
| 19 | all = cluster.dup << operation |
| 20 | |
Pawel Wieczorek | 6b1f78b | 2019-07-26 14:04:39 +0200 | [diff] [blame^] | 21 | $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 |
| 25 | SCRIPT |
| 26 | |
Pawel Wieczorek | 5ee9206 | 2019-07-26 13:58:02 +0200 | [diff] [blame] | 27 | $add_to_docker_group = <<-SCRIPT |
| 28 | USER="$1" |
| 29 | usermod -aG docker "$USER" |
| 30 | SCRIPT |
| 31 | |
Pawel Wieczorek | 6b1f78b | 2019-07-26 14:04:39 +0200 | [diff] [blame^] | 32 | $install_sshpass = <<-SCRIPT |
| 33 | apt-get update |
| 34 | apt-get install sshpass |
| 35 | SCRIPT |
| 36 | |
| 37 | $generate_key = <<-SCRIPT |
| 38 | KEY_FILE="$1" |
| 39 | ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N "" |
| 40 | SCRIPT |
| 41 | |
Pawel Wieczorek | 9cf6f59 | 2019-07-26 13:40:23 +0200 | [diff] [blame] | 42 | $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 |
| 50 | SCRIPT |
| 51 | |
Pawel Wieczorek | 34e5932 | 2019-07-26 13:29:50 +0200 | [diff] [blame] | 52 | $link_dotfiles = <<-SCRIPT |
| 53 | for rc in /vagrant/dot_*; do |
| 54 | ln -sf "$rc" "${HOME}/.${rc##*dot_}" |
| 55 | done |
| 56 | SCRIPT |
| 57 | |
Pawel Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 58 | Vagrant.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 Wieczorek | 6b1f78b | 2019-07-26 14:04:39 +0200 | [diff] [blame^] | 76 | config.vm.provision :shell, run: "always", inline: $replace_dns, args: host_ip |
Pawel Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 77 | |
| 78 | if machine[:name] == 'control' |
| 79 | config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-controlnode.sh" |
Pawel Wieczorek | 5ee9206 | 2019-07-26 13:58:02 +0200 | [diff] [blame] | 80 | config.vm.provision :shell, inline: $add_to_docker_group, args: vagrant_user |
Pawel Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 81 | end |
| 82 | |
| 83 | if machine[:name] == 'worker' |
| 84 | config.vm.provision :shell, path: "../../tools/dublin/imported/openstack-k8s-workernode.sh" |
Pawel Wieczorek | 5ee9206 | 2019-07-26 13:58:02 +0200 | [diff] [blame] | 85 | config.vm.provision :shell, inline: $add_to_docker_group, args: vagrant_user |
Pawel Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 86 | end |
| 87 | |
| 88 | if machine[:name] == 'operator' |
Pawel Wieczorek | 34e5932 | 2019-07-26 13:29:50 +0200 | [diff] [blame] | 89 | 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 Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 94 | config.vm.provision :shell, path: "../../tools/dublin/get_rke.sh" |
| 95 | |
Pawel Wieczorek | 6b1f78b | 2019-07-26 14:04:39 +0200 | [diff] [blame^] | 96 | config.vm.provision :shell, inline: $install_sshpass |
| 97 | config.vm.provision :shell, privileged: false, inline: $generate_key, args: operator_key |
Pawel Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 98 | |
| 99 | ips = "" |
| 100 | cluster.each { |node| ips << node[:ip] << " " } |
Pawel Wieczorek | 9cf6f59 | 2019-07-26 13:40:23 +0200 | [diff] [blame] | 101 | 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 Wieczorek | b7f0811 | 2019-07-19 19:10:07 +0200 | [diff] [blame] | 107 | end |
| 108 | end |
| 109 | end |
| 110 | end |