2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) Ericsson AB and others
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 check_prerequisites() {
12 echo "Info : Check prerequisites"
14 #-------------------------------------------------------------------------------
15 # We shouldn't be running as root
16 #-------------------------------------------------------------------------------
17 if [[ "$(whoami)" == "root" ]]; then
18 echo "ERROR : This script must not be run as root!"
19 echo " Please switch to a regular user before running the script."
23 #-------------------------------------------------------------------------------
24 # Check for passwordless sudo
25 #-------------------------------------------------------------------------------
26 if ! sudo -n "true"; then
27 echo "ERROR : passwordless sudo is needed for '$(id -nu)' user."
31 #-------------------------------------------------------------------------------
32 # Check if SSH key exists
33 #-------------------------------------------------------------------------------
34 if [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
35 echo "ERROR : You must have SSH keypair in order to run this script!"
39 #-------------------------------------------------------------------------------
40 # We are using sudo so we need to make sure that env_reset is not present
41 #-------------------------------------------------------------------------------
42 sudo sed -i "s/^Defaults.*env_reset/#&/" /etc/sudoers
44 #-------------------------------------------------------------------------------
45 # Check if Ansible is installed
46 #-------------------------------------------------------------------------------
47 if ! command -v ansible &> /dev/null; then
48 echo "ERROR : Ansible not found. Please install."
52 #-------------------------------------------------------------------------------
53 # Check is yq is installed
54 #-------------------------------------------------------------------------------
55 if ! command -v yq &> /dev/null; then
56 echo "ERROR : yq not found. Please install."
60 #-------------------------------------------------------------------------------
61 # Check is libvirt is installed
62 #-------------------------------------------------------------------------------
63 if ! command -v virsh &> /dev/null; then
64 echo "ERROR : Libvirt not found. Please install."
68 #-------------------------------------------------------------------------------
69 # Check if user belongs to libvirt's group
70 #-------------------------------------------------------------------------------
71 libvirt_group="libvirt"
72 # shellcheck disable=SC1091
73 source /etc/os-release || source /usr/lib/os-release
74 if [ "${ID,,}" == "ubuntu" ] && [ "$VERSION_ID" == "16.04" ]; then
77 if ! groups | grep " $libvirt_group "; then
78 echo "ERROR : $(id -nu) user doesn't belong to $libvirt_group group."
90 if [[ "$host" == "" ]]; then
91 echo "ERROR : get_ip - host parameter not provided"
95 PXE_NETWORK=$(yq r "$CURRENTPATH"/hw_config/"$VENDOR"/idf.yaml engine.pxe_network)
96 if [[ "$PXE_NETWORK" == "" ]]; then
97 echo "ERROR : PXE network for jump VM not defined in IDF."
101 PXE_IF_INDEX=$(yq r "$CURRENTPATH"/hw_config/"${VENDOR}"/idf.yaml idf.net_config."$PXE_NETWORK".interface)
102 if [[ "$PXE_IF_INDEX" == "" ]]; then
103 echo "ERROR : Index of PXE interface not found in IDF."
107 PXE_IF_IP=$(yq r "$CURRENTPATH"/hw_config/"${VENDOR}"/pdf.yaml "$host".interfaces["$PXE_IF_INDEX"].address)
108 if [[ "$PXE_IF_IP" == "" ]]; then
109 echo "ERROR : IP of PXE interface not found in PDF."
116 ip=$(get_host_pxe_ip "jumphost")
121 # Copy files needed by Infra engine & BMRA in the jumphost VM
123 scp -r -o StrictHostKeyChecking=no \
124 "$CURRENTPATH"/{hw_config/"$VENDOR"/,sw_config/"$INSTALLER"/} \
125 "$USERNAME@$(get_vm_ip):$PROJECT_ROOT"
130 # shellcheck disable=SC2087
131 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
132 # Install and run cloud-infra
133 if [ ! -d "${PROJECT_ROOT}/engine" ]; then
134 ssh-keygen -t rsa -N "" -f ${PROJECT_ROOT}/.ssh/id_rsa
135 git clone https://gerrit.nordix.org/infra/engine.git
136 cp $PROJECT_ROOT/$VENDOR/{pdf.yaml,idf.yaml} \
137 ${PROJECT_ROOT}/engine/engine
139 cd ${PROJECT_ROOT}/engine/engine
140 ./deploy.sh -s ironic -d centos7 \
141 -p file:///${PROJECT_ROOT}/engine/engine/pdf.yaml \
142 -i file:///${PROJECT_ROOT}/engine/engine/idf.yaml
146 # Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup)
148 MASTER_IP=$(get_host_pxe_ip "nodes[0]")
149 WORKER_IP=$(get_host_pxe_ip "nodes[1]")
151 # shellcheck disable=SC2087
152 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
153 ssh -o StrictHostKeyChecking=no root@$MASTER_IP \
154 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
155 ssh -o StrictHostKeyChecking=no root@$WORKER_IP \
156 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
160 # k8s Provisioning (currently BMRA)
162 # shellcheck disable=SC2087
163 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
165 if ! command -v docker; then
166 curl -fsSL https://get.docker.com/ | sh
167 printf "Waiting for docker service..."
168 until sudo docker info; do
173 if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then
174 git clone --recurse-submodules --depth 1 https://github.com/intel/container-experience-kits.git -b v1.4.1 ${PROJECT_ROOT}/container-experience-kits/
175 cp -r ${PROJECT_ROOT}/container-experience-kits/examples/group_vars ${PROJECT_ROOT}/container-experience-kits/
176 #TODO Remove this once the reported issue is fixed in the next BMRA Release
177 sed -i '/\openshift/a \ extra_args: --ignore-installed PyYAML' \
178 ${PROJECT_ROOT}/container-experience-kits/roles/net-attach-defs-create/tasks/main.yml
180 cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini \
181 ${PROJECT_ROOT}/container-experience-kits/
182 cp ${PROJECT_ROOT}/${INSTALLER}/{all.yml,kube-node.yml} \
183 ${PROJECT_ROOT}/container-experience-kits/group_vars/
184 sudo docker run --rm \
185 -e ANSIBLE_CONFIG=/bmra/ansible.cfg \
186 -v ${PROJECT_ROOT}/container-experience-kits:/bmra \
187 -v ~/.ssh/:/root/.ssh/ rihabbanday/bmra-install:centos \
188 ansible-playbook -i /bmra/inventory.ini /bmra/playbooks/cluster.yml