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 libvirt is installed
54 #-------------------------------------------------------------------------------
55 if ! command -v virsh &> /dev/null; then
56 echo "ERROR : Libvirt not found. Please install."
60 #-------------------------------------------------------------------------------
61 # Check if user belongs to libvirt's group
62 #-------------------------------------------------------------------------------
63 libvirt_group="libvirt"
64 # shellcheck disable=SC1091
65 source /etc/os-release || source /usr/lib/os-release
66 if [ "${ID,,}" == "ubuntu" ] && [ "$VERSION_ID" == "16.04" ]; then
69 if ! groups | grep " $libvirt_group "; then
70 echo "ERROR : $(id -nu) user doesn't belong to $libvirt_group group."
82 if [[ "$host" == "" ]]; then
83 echo "ERROR : get_ip - host parameter not provided"
87 PXE_NETWORK=$(yq r "$CURRENTPATH"/hw_config/"$VENDOR"/idf.yaml engine.pxe_network)
88 if [[ "$PXE_NETWORK" == "" ]]; then
89 echo "ERROR : PXE network for jump VM not defined in IDF."
93 PXE_IF_INDEX=$(yq r "$CURRENTPATH"/hw_config/"${VENDOR}"/idf.yaml idf.net_config."$PXE_NETWORK".interface)
94 if [[ "$PXE_IF_INDEX" == "" ]]; then
95 echo "ERROR : Index of PXE interface not found in IDF."
99 PXE_IF_IP=$(yq r "$CURRENTPATH"/hw_config/"${VENDOR}"/pdf.yaml "$host".interfaces["$PXE_IF_INDEX"].address)
100 if [[ "$PXE_IF_IP" == "" ]]; then
101 echo "ERROR : IP of PXE interface not found in PDF."
108 ip=$(get_host_pxe_ip "jumphost")
113 # Copy files needed by Infra engine & BMRA in the jumphost VM
115 scp -r -o StrictHostKeyChecking=no \
116 "$CURRENTPATH"/{hw_config/"$VENDOR"/,sw_config/"$INSTALLER"/} \
117 "$USERNAME@$(get_vm_ip):$PROJECT_ROOT"
122 # shellcheck disable=SC2087
123 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
124 # Install and run cloud-infra
125 if [ ! -d "${PROJECT_ROOT}/engine" ]; then
126 ssh-keygen -t rsa -N "" -f ${PROJECT_ROOT}/.ssh/id_rsa
127 git clone https://gerrit.nordix.org/infra/engine.git
128 cp $PROJECT_ROOT/$VENDOR/{pdf.yaml,idf.yaml} \
129 ${PROJECT_ROOT}/engine/engine
131 cd ${PROJECT_ROOT}/engine/engine
132 ./deploy.sh -s ironic -d centos7 \
133 -p file:///${PROJECT_ROOT}/engine/engine/pdf.yaml \
134 -i file:///${PROJECT_ROOT}/engine/engine/idf.yaml
138 # Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup)
140 MASTER_IP=$(get_host_pxe_ip "nodes[0]")
141 WORKER_IP=$(get_host_pxe_ip "nodes[1]")
143 # shellcheck disable=SC2087
144 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
145 ssh -o StrictHostKeyChecking=no root@$MASTER_IP \
146 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
147 ssh -o StrictHostKeyChecking=no root@$WORKER_IP \
148 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
152 # k8s Provisioning (currently BMRA)
154 # shellcheck disable=SC2087
155 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
157 if ! command -v docker; then
158 curl -fsSL https://get.docker.com/ | sh
159 printf "Waiting for docker service..."
160 until sudo docker info; do
165 if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then
166 git clone --recurse-submodules --depth 1 https://github.com/intel/container-experience-kits.git -b v1.4.1 ${PROJECT_ROOT}/container-experience-kits/
167 cp -r ${PROJECT_ROOT}/container-experience-kits/examples/group_vars ${PROJECT_ROOT}/container-experience-kits/
168 #TODO Remove this once the reported issue is fixed in the next BMRA Release
169 sed -i '/\openshift/a \ extra_args: --ignore-installed PyYAML' \
170 ${PROJECT_ROOT}/container-experience-kits/roles/net-attach-defs-create/tasks/main.yml
172 cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini \
173 ${PROJECT_ROOT}/container-experience-kits/
174 cp ${PROJECT_ROOT}/${INSTALLER}/{all.yml,kube-node.yml} \
175 ${PROJECT_ROOT}/container-experience-kits/group_vars/
176 sudo docker run --rm \
177 -e ANSIBLE_CONFIG=/bmra/ansible.cfg \
178 -v ${PROJECT_ROOT}/container-experience-kits:/bmra \
179 -v ~/.ssh/:/root/.ssh/ rihabbanday/bmra-install:centos \
180 ansible-playbook -i /bmra/inventory.ini /bmra/playbooks/cluster.yml