blob: cbdb7ac7e34ed9c7e3453225e236efc7620b7a30 [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}"
118 git clone -b "$BRANCH" https://git.onap.org/oom --recurse-submodules
119SCRIPT
120
121$get_helm_plugins = "cp -R ${HOME}/oom/kubernetes/helm/plugins/ ${HOME}/.helm"
122
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100123$setup_helm_cluster = <<-SCRIPT
124 export KUBECONFIG="${HOME}/.kube/config.onap"
125 kubectl config use-context onap
126 kubectl -n kube-system create serviceaccount tiller
127 kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
128 helm init --service-account tiller
129 kubectl -n kube-system rollout status deploy/tiller-deploy
130SCRIPT
131
132# FIXME: replace sleep command with helm repo readiness probe
133$setup_helm_repo = <<-SCRIPT
134 helm serve &
135 sleep 3
136 helm repo add local http://127.0.0.1:8879
137 make -C ${HOME}/oom/kubernetes all
138 make -C ${HOME}/oom/kubernetes onap
139SCRIPT
140
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100141$deploy_onap = <<-SCRIPT
142 ENV="$1"
143 export $(cat "$ENV" | xargs)
144
145 encrypt () {
146 KEY="${HOME}/oom/kubernetes/so/resources/config/mso/encryption.key"
147 echo -n "$1" \
148 | openssl aes-128-ecb -e -K `cat "$KEY"` -nosalt \
149 | xxd -c 256 -p
150 }
151
152 export OPENSTACK_ENCRYPTED_PASSWORD="$(encrypt $OPENSTACK_PASSWORD)"
153
154 export KUBECONFIG="${HOME}/.kube/config.onap"
155
156 OVERRIDE="${HOME}/oom/kubernetes/onap/resources/environments/minimal-onap.yaml"
157 helm deploy minimal local/onap --namespace onap -f "$OVERRIDE" --verbose --timeout 900
158SCRIPT
159
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100160Vagrant.configure('2') do |config|
161 all.each do |machine|
162 config.vm.define machine[:name] do |config|
163 config.vm.box = vm_box
164 config.vm.hostname = machine[:hostname]
165
166 config.vm.provider :virtualbox do |v|
167 v.name = machine[:name]
Pawel Wieczorek3cb78212019-12-09 16:00:47 +0100168 v.memory = machine[:memory]
169 v.cpus = machine[:cpus]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100170 end
171
172 config.vm.provider :libvirt do |v|
Pawel Wieczorek3cb78212019-12-09 16:00:47 +0100173 v.memory = machine[:memory]
174 v.cpus = machine[:cpus]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100175 end
176
177 config.vm.network :private_network, ip: machine[:ip]
178 config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip
179
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +0100180 if machine[:name] == 'devstack'
181 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: "Vagrantfile"
182
183 config.vm.provision "enable_ipv6", type: :shell, run: "always", inline: $enable_ipv6
184 config.vm.provision "setup_devstack", type: :shell, privileged: false, inline: $setup_devstack, args: os_config
185 end
186
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100187 if machine[:name] == 'control'
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100188 config.vm.provision "customize_control", type: :shell, path: "tools/imported/openstack-k8s-controlnode.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100189 config.vm.provision "fix_groups_control", type: :shell, inline: $add_to_docker_group, args: vagrant_user
190 end
191
192 if machine[:name] == 'worker'
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100193 config.vm.provision "customize_worker", type: :shell, path: "tools/imported/openstack-k8s-workernode.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100194 config.vm.provision "fix_group_worker", type: :shell, inline: $add_to_docker_group, args: vagrant_user
195 end
196
197 if machine[:name] == 'operator'
198 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: "Vagrantfile"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100199
200 config.vm.provision "setup_debconf", type: :shell, inline: $setup_debconf
201 config.vm.provision "link_apt_prefs", type: :shell, run: "always" do |s|
202 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100203 s.args = [synced_folder_tools_config, apt_prefs, apt_prefs_dir]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100204 end
205 config.vm.provision "link_dotfiles_root", type: :shell, run: "always" do |s|
206 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100207 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100208 end
209 config.vm.provision "link_dotfiles_user", type: :shell, run: "always" do |s|
210 s.privileged = false
211 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100212 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100213 end
214
215 config.vm.provision "install_sshpass", type: :shell, inline: $install_sshpass
216 config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: operator_key
217
218 ips = ""
219 cluster.each { |node| ips << node[:ip] << " " }
220 config.vm.provision "deploy_key", type: :shell do |s|
221 s.privileged = false
222 s.inline = $deploy_key
223 s.args = [operator_key, vagrant_user, ips]
224 s.env = {'PASSWORD': vagrant_password}
225 end
226
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100227 config.vm.provision "get_rke", type: :shell, path: "tools/get_rke.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100228 config.vm.provision "link_cluster_yml", type: :shell, run: "always" do |s|
229 s.privileged = false
230 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100231 s.args = [synced_folder_config, cluster_yml, "$HOME"]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100232 end
233
234 config.vm.post_up_message = operation_post_msg
235 config.vm.provision "rke_up", type: :shell, run: "never", privileged: false, inline: $rke_up
236 config.trigger.before :destroy do |trigger|
237 trigger.warn = "Removing cluster"
238 trigger.run_remote = {privileged: false, inline: $rke_down}
239 end
240
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100241 config.vm.provision "get_kubectl", type: :shell, path: "tools/get_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100242 config.vm.provision "setup_kubectl", type: :shell, run: "never" do |s|
243 s.privileged = false
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100244 s.path = "tools/setup_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100245 end
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100246 config.vm.provision "get_helm", type: :shell, path: "tools/get_helm.sh"
247 config.vm.provision "get_oom", type: :shell, privileged: false, inline: $get_oom
248 config.vm.provision "get_helm_plugins", type: :shell, privileged: false, inline: $get_helm_plugins
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100249 config.vm.provision "install_make", type: :shell, inline: $install_make
250 config.vm.provision "setup_helm_cluster", type: :shell, run: "never", privileged: false, inline: $setup_helm_cluster
251 config.vm.provision "setup_helm_repo", type: :shell, run: "never", privileged: false, inline: $setup_helm_repo
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100252 config.vm.provision "deploy_onap", type: :shell, run: "never" do |s|
253 s.privileged = false
254 s.inline = $deploy_onap
255 s.args = os_env
256 end
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100257 end
258 end
259 end
260end