blob: e12c035bfdc40d0b3e39640770ef18bd0b293be8 [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
Pawel Wieczorek6efe9412020-01-07 15:28:55 +0100121$get_helm_plugins = "mkdir -p ${HOME}/.helm && cp -R ${HOME}/oom/kubernetes/helm/plugins/ ${HOME}/.helm"
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100122
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'
Pawel Wieczorekba88f292020-01-27 17:34:05 +0100198 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: ["Vagrantfile", "operator"]
Pawel Wieczorekb0accc32020-01-16 16:21:02 +0100199 config.vm.synced_folder "./operator", "/home/#{vagrant_user}", type: "sshfs", reverse: true, sshfs_opts_append: "-o nonempty"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100200
201 config.vm.provision "setup_debconf", type: :shell, inline: $setup_debconf
202 config.vm.provision "link_apt_prefs", type: :shell, run: "always" do |s|
203 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100204 s.args = [synced_folder_tools_config, apt_prefs, apt_prefs_dir]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100205 end
206 config.vm.provision "link_dotfiles_root", type: :shell, run: "always" do |s|
207 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100208 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100209 end
210 config.vm.provision "link_dotfiles_user", type: :shell, run: "always" do |s|
211 s.privileged = false
212 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100213 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100214 end
215
216 config.vm.provision "install_sshpass", type: :shell, inline: $install_sshpass
217 config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: operator_key
218
219 ips = ""
220 cluster.each { |node| ips << node[:ip] << " " }
221 config.vm.provision "deploy_key", type: :shell do |s|
222 s.privileged = false
223 s.inline = $deploy_key
224 s.args = [operator_key, vagrant_user, ips]
225 s.env = {'PASSWORD': vagrant_password}
226 end
227
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100228 config.vm.provision "get_rke", type: :shell, path: "tools/get_rke.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100229 config.vm.provision "link_cluster_yml", type: :shell, run: "always" do |s|
230 s.privileged = false
231 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100232 s.args = [synced_folder_config, cluster_yml, "$HOME"]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100233 end
234
235 config.vm.post_up_message = operation_post_msg
236 config.vm.provision "rke_up", type: :shell, run: "never", privileged: false, inline: $rke_up
237 config.trigger.before :destroy do |trigger|
238 trigger.warn = "Removing cluster"
239 trigger.run_remote = {privileged: false, inline: $rke_down}
240 end
241
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100242 config.vm.provision "get_kubectl", type: :shell, path: "tools/get_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100243 config.vm.provision "setup_kubectl", type: :shell, run: "never" do |s|
244 s.privileged = false
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100245 s.path = "tools/setup_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100246 end
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100247 config.vm.provision "get_helm", type: :shell, path: "tools/get_helm.sh"
248 config.vm.provision "get_oom", type: :shell, privileged: false, inline: $get_oom
249 config.vm.provision "get_helm_plugins", type: :shell, privileged: false, inline: $get_helm_plugins
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100250 config.vm.provision "install_make", type: :shell, inline: $install_make
251 config.vm.provision "setup_helm_cluster", type: :shell, run: "never", privileged: false, inline: $setup_helm_cluster
252 config.vm.provision "setup_helm_repo", type: :shell, run: "never", privileged: false, inline: $setup_helm_repo
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100253 config.vm.provision "deploy_onap", type: :shell, run: "never" do |s|
254 s.privileged = false
255 s.inline = $deploy_onap
256 s.args = os_env
257 end
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100258 end
259 end
260 end
261end