blob: 5272dd6afcf950444e49a834424603af5dbafc07 [file] [log] [blame]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +01001# -*- mode: ruby -*-
2# -*- coding: utf-8 -*-
3
4host_ip = "192.168.121.1"
5operator_key = "${HOME}/.ssh/onap-key"
6vagrant_user = "vagrant"
7vagrant_password = "vagrant"
8synced_folder_main = "/vagrant"
9synced_folder_config = "#{synced_folder_main}/config"
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +010010synced_folder_tools_config = "#{synced_folder_main}/tools/config"
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +010011os_config = "#{synced_folder_config}/local.conf"
Pawel Wieczorek0d01b782019-12-09 16:20:45 +010012os_env = "#{synced_folder_config}/dot_env"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010013cluster_yml = "cluster.yml"
14apt_prefs_dir = "/etc/apt/apt.conf.d"
15apt_prefs = "95silent-approval"
16
Pawel Wieczorek3cb78212019-12-09 16:00:47 +010017vm_memory = 1 * 1024
18vm_memory_os = 6 * 1024
19vm_memory_onap = 12 * 1024
20vm_cpu = 1
21vm_cpus = 2
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010022vm_box = "generic/ubuntu1804"
23
Pawel Wieczorek3cb78212019-12-09 16:00:47 +010024operation = { name: 'operator', hostname: 'operator', ip: '172.17.4.254', cpus: vm_cpu, memory: vm_memory }
25devstack = { name: 'devstack', hostname: 'devstack', ip: '172.17.4.200', cpus: vm_cpus, memory: vm_memory_os }
26control = { name: 'control', hostname: 'control', ip: '172.17.4.100', cpus: vm_cpu, memory: vm_memory }
27worker = { name: 'worker', hostname: 'worker', ip: '172.17.4.101', cpus: vm_cpus, memory: vm_memory_onap }
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010028
Pawel Wieczorek3cb78212019-12-09 16:00:47 +010029cluster = [] << control << worker
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +010030all = cluster.dup << operation << devstack
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010031
Pawel Wieczorek0d01b782019-12-09 16:20:45 +010032operation_post_msg = "Run: \"vagrant provision #{operation[:name]} --provision-with=rke_up,setup_kubectl,setup_helm_cluster,setup_helm_repo,deploy_onap\" to complete ONAP deployment"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010033
34$replace_dns = <<-SCRIPT
35 HOST_IP="$1"
36 rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
37 echo nameserver "$HOST_IP" | tee /etc/resolv.conf
38SCRIPT
39
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +010040$enable_ipv6 = <<-SCRIPT
41 sed -i'' 's/net.ipv6.conf.all.disable_ipv6.*$/net.ipv6.conf.all.disable_ipv6 = 0/' /etc/sysctl.conf
42 sysctl -p
43SCRIPT
44
45$setup_devstack = <<-SCRIPT
46 CONFIG="$1"
47 git clone https://opendev.org/openstack/devstack
48 cd devstack
49 cp "$CONFIG" .
50 ./stack.sh
51SCRIPT
52
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010053$add_to_docker_group = <<-SCRIPT
54 USER="$1"
55 echo "Adding ${USER} to 'docker' group"
56 usermod -aG docker "$USER"
57SCRIPT
58
59$setup_debconf = <<-SCRIPT
60 echo "Setting debconf frontend to noninteractive"
61 sed -i'.orig' '/^Config:/a Frontend: noninteractive' /etc/debconf.conf
62SCRIPT
63
64$install_sshpass = <<-SCRIPT
65 apt-get update
66 echo "Installing 'sshpass'"
67 apt-get install sshpass
68SCRIPT
69
Pawel Wieczorek0664ac42019-12-09 16:16:48 +010070$install_make = <<-SCRIPT
71 apt-get update
72 echo "Installing 'make'"
73 apt-get install make
74SCRIPT
75
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010076$generate_key = <<-SCRIPT
77 KEY_FILE="$1"
78 echo "Generating SSH key (${KEY_FILE})"
79 ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N ""
80SCRIPT
81
82$deploy_key = <<-SCRIPT
83 KEY="$1"
84 USER="$2"
85 PASS="$PASSWORD"
86 IPS="$3"
87 echo "Deploying ${KEY} for ${USER}"
88 for ip in $IPS; do
89 echo "on ${ip}"
90 sshpass -p "$PASS" ssh-copy-id -o StrictHostKeyChecking=no -i "$KEY" "${USER}@${ip}"
91 done
92SCRIPT
93
94$link_dotfiles = <<-SCRIPT
95 SYNC_DIR="$1"
96 for rc in ${SYNC_DIR}/dot_*; do
97 src="$rc"
98 dst="${HOME}/.${rc##*dot_}"
99 echo "Symlinking ${src} to ${dst}"
100 ln -sf "$src" "$dst"
101 done
102SCRIPT
103
104$link_file = <<-SCRIPT
105 SYNC_DIR="$1"
106 FILE="$2"
107 src="${SYNC_DIR}/${FILE}"
108 dst="$3"
109 echo "Symlinking ${src} to ${dst}"
110 ln -sf "$src" "$dst"
111SCRIPT
112
113$rke_up = "rke up"
114$rke_down = "rke remove --force"
115
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100116$get_oom = <<-SCRIPT
117 BRANCH="${1:-5.0.1-ONAP}"
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100118 REPO="${2:-https://git.onap.org/oom}"
119 git clone -b "$BRANCH" "$REPO" --recurse-submodules
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100120SCRIPT
121
Pawel Wieczorek6efe9412020-01-07 15:28:55 +0100122$get_helm_plugins = "mkdir -p ${HOME}/.helm && cp -R ${HOME}/oom/kubernetes/helm/plugins/ ${HOME}/.helm"
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100123
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100124$setup_helm_cluster = <<-SCRIPT
125 export KUBECONFIG="${HOME}/.kube/config.onap"
126 kubectl config use-context onap
127 kubectl -n kube-system create serviceaccount tiller
128 kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
129 helm init --service-account tiller
130 kubectl -n kube-system rollout status deploy/tiller-deploy
131SCRIPT
132
133# FIXME: replace sleep command with helm repo readiness probe
134$setup_helm_repo = <<-SCRIPT
135 helm serve &
136 sleep 3
137 helm repo add local http://127.0.0.1:8879
138 make -C ${HOME}/oom/kubernetes all
139 make -C ${HOME}/oom/kubernetes onap
140SCRIPT
141
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100142$deploy_onap = <<-SCRIPT
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100143 OVERRIDE="${1:-${HOME}/oom/kubernetes/onap/resources/environments/minimal-onap.yaml}"
144
145 ENV="${2:-#{os_env}}"
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100146 export $(cat "$ENV" | xargs)
147
148 encrypt () {
149 KEY="${HOME}/oom/kubernetes/so/resources/config/mso/encryption.key"
150 echo -n "$1" \
151 | openssl aes-128-ecb -e -K `cat "$KEY"` -nosalt \
152 | xxd -c 256 -p
153 }
154
155 export OPENSTACK_ENCRYPTED_PASSWORD="$(encrypt $OPENSTACK_PASSWORD)"
156
157 export KUBECONFIG="${HOME}/.kube/config.onap"
158
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100159 helm deploy minimal local/onap --namespace onap -f "$OVERRIDE" --verbose --timeout 900
160SCRIPT
161
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100162Vagrant.configure('2') do |config|
163 all.each do |machine|
164 config.vm.define machine[:name] do |config|
165 config.vm.box = vm_box
166 config.vm.hostname = machine[:hostname]
167
168 config.vm.provider :virtualbox do |v|
169 v.name = machine[:name]
Pawel Wieczorek3cb78212019-12-09 16:00:47 +0100170 v.memory = machine[:memory]
171 v.cpus = machine[:cpus]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100172 end
173
174 config.vm.provider :libvirt do |v|
Pawel Wieczorek3cb78212019-12-09 16:00:47 +0100175 v.memory = machine[:memory]
176 v.cpus = machine[:cpus]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100177 end
178
179 config.vm.network :private_network, ip: machine[:ip]
180 config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip
181
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +0100182 if machine[:name] == 'devstack'
183 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: "Vagrantfile"
184
185 config.vm.provision "enable_ipv6", type: :shell, run: "always", inline: $enable_ipv6
186 config.vm.provision "setup_devstack", type: :shell, privileged: false, inline: $setup_devstack, args: os_config
187 end
188
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100189 if machine[:name] == 'control'
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100190 config.vm.provision "customize_control", type: :shell, path: "tools/imported/openstack-k8s-controlnode.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100191 config.vm.provision "fix_groups_control", type: :shell, inline: $add_to_docker_group, args: vagrant_user
192 end
193
194 if machine[:name] == 'worker'
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100195 config.vm.provision "customize_worker", type: :shell, path: "tools/imported/openstack-k8s-workernode.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100196 config.vm.provision "fix_group_worker", type: :shell, inline: $add_to_docker_group, args: vagrant_user
197 end
198
199 if machine[:name] == 'operator'
Pawel Wieczorekba88f292020-01-27 17:34:05 +0100200 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: ["Vagrantfile", "operator"]
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100201 config.vm.synced_folder "~/.ssh", "/home/#{vagrant_user}/.ssh", type: "rsync", rsync__exclude: "authorized_keys"
Pawel Wieczorekb0accc32020-01-16 16:21:02 +0100202 config.vm.synced_folder "./operator", "/home/#{vagrant_user}", type: "sshfs", reverse: true, sshfs_opts_append: "-o nonempty"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100203
204 config.vm.provision "setup_debconf", type: :shell, inline: $setup_debconf
205 config.vm.provision "link_apt_prefs", type: :shell, run: "always" do |s|
206 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100207 s.args = [synced_folder_tools_config, apt_prefs, apt_prefs_dir]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100208 end
209 config.vm.provision "link_dotfiles_root", type: :shell, run: "always" do |s|
210 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100211 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100212 end
213 config.vm.provision "link_dotfiles_user", type: :shell, run: "always" do |s|
214 s.privileged = false
215 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100216 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100217 end
218
219 config.vm.provision "install_sshpass", type: :shell, inline: $install_sshpass
220 config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: operator_key
221
222 ips = ""
223 cluster.each { |node| ips << node[:ip] << " " }
224 config.vm.provision "deploy_key", type: :shell do |s|
225 s.privileged = false
226 s.inline = $deploy_key
227 s.args = [operator_key, vagrant_user, ips]
228 s.env = {'PASSWORD': vagrant_password}
229 end
230
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100231 config.vm.provision "get_rke", type: :shell, path: "tools/get_rke.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100232 config.vm.provision "link_cluster_yml", type: :shell, run: "always" do |s|
233 s.privileged = false
234 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100235 s.args = [synced_folder_config, cluster_yml, "$HOME"]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100236 end
237
238 config.vm.post_up_message = operation_post_msg
239 config.vm.provision "rke_up", type: :shell, run: "never", privileged: false, inline: $rke_up
240 config.trigger.before :destroy do |trigger|
241 trigger.warn = "Removing cluster"
242 trigger.run_remote = {privileged: false, inline: $rke_down}
243 end
244
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100245 config.vm.provision "get_kubectl", type: :shell, path: "tools/get_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100246 config.vm.provision "setup_kubectl", type: :shell, run: "never" do |s|
247 s.privileged = false
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100248 s.path = "tools/setup_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100249 end
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100250 config.vm.provision "get_helm", type: :shell, path: "tools/get_helm.sh"
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100251 config.vm.provision "get_oom", type: :shell do |s|
252 s.privileged = false
253 s.inline = $get_oom
254 end
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100255 config.vm.provision "get_helm_plugins", type: :shell, privileged: false, inline: $get_helm_plugins
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100256 config.vm.provision "install_make", type: :shell, inline: $install_make
257 config.vm.provision "setup_helm_cluster", type: :shell, run: "never", privileged: false, inline: $setup_helm_cluster
258 config.vm.provision "setup_helm_repo", type: :shell, run: "never", privileged: false, inline: $setup_helm_repo
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100259 config.vm.provision "deploy_onap", type: :shell, run: "never" do |s|
260 s.privileged = false
261 s.inline = $deploy_onap
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100262 end
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100263 end
264 end
265 end
266end