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 ##############################################################################
12 _print_msg "INFO" "$1"
16 _print_msg "ERROR" "$1"
21 echo "$(date +%H:%M:%S) - $1: $2"
30 check_prerequisites() {
31 info "Check prerequisites"
33 #-------------------------------------------------------------------------------
34 # We shouldn't be running as root
35 #-------------------------------------------------------------------------------
36 if [[ "$(whoami)" == "root" ]]; then
37 error "This script must not be run as root! Please switch to a regular user before running the script."
40 #-------------------------------------------------------------------------------
41 # Check for passwordless sudo
42 #-------------------------------------------------------------------------------
43 if ! sudo -n "true"; then
44 error "passwordless sudo is needed for '$(id -nu)' user."
47 #-------------------------------------------------------------------------------
48 # Check if SSH key exists
49 #-------------------------------------------------------------------------------
50 if [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
51 error "You must have SSH keypair in order to run this script!"
54 #-------------------------------------------------------------------------------
55 # We are using sudo so we need to make sure that env_reset is not present
56 #-------------------------------------------------------------------------------
57 sudo sed -i "s/^Defaults.*env_reset/#&/" /etc/sudoers
59 #-------------------------------------------------------------------------------
60 # Check if some tools are installed
61 #-------------------------------------------------------------------------------
62 for tool in ansible yq virsh; do
63 if ! command -v "$tool" &> /dev/null; then
64 error "$tool 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 error "$(id -nu) user doesn't belong to $libvirt_group group."
82 # Get jumphost VM PXE IP
89 assert_non_empty "$host" "get_ip - host parameter not provided"
91 PXE_NETWORK=$(yq r "$CURRENTPATH"/hw_config/"$VENDOR"/idf.yaml engine.pxe_network)
92 assert_non_empty "$PXE_NETWORK" "PXE network for jump VM not defined in IDF."
94 PXE_IF_INDEX=$(yq r "$CURRENTPATH"/hw_config/"${VENDOR}"/idf.yaml idf.net_config."$PXE_NETWORK".interface)
95 assert_non_empty "$PXE_IF_INDEX" "Index of PXE interface not found in IDF."
97 PXE_IF_IP=$(yq r "$CURRENTPATH"/hw_config/"${VENDOR}"/pdf.yaml "$host".interfaces["$PXE_IF_INDEX"].address)
98 assert_non_empty "$PXE_IF_IP" "IP of PXE interface not found in PDF."
105 ip=$(get_host_pxe_ip "jumphost")
109 # Copy files needed by Infra engine & BMRA in the jumphost VM
111 scp -r -o StrictHostKeyChecking=no \
112 "$CURRENTPATH"/{hw_config/"$VENDOR"/,sw_config/"$INSTALLER"/} \
113 "$USERNAME@$(get_vm_ip):$PROJECT_ROOT"
118 # shellcheck disable=SC2087
119 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
120 # Install and run cloud-infra
121 if [ ! -d "${PROJECT_ROOT}/engine" ]; then
122 ssh-keygen -t rsa -N "" -f ${PROJECT_ROOT}/.ssh/id_rsa
123 git clone https://gerrit.nordix.org/infra/engine.git
124 cp $PROJECT_ROOT/$VENDOR/{pdf.yaml,idf.yaml} \
125 ${PROJECT_ROOT}/engine/engine
127 cd ${PROJECT_ROOT}/engine/engine
128 ./deploy.sh -s ironic -d centos7 \
129 -p file:///${PROJECT_ROOT}/engine/engine/pdf.yaml \
130 -i file:///${PROJECT_ROOT}/engine/engine/idf.yaml
134 # Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup)
136 # Set Upper limit of number nodes in RI2 cluster (starting from 0)
137 NODE_MAX_ID=$(($(yq r "$CURRENTPATH"/hw_config/"$VENDOR"/idf.yaml --length idf.kubespray.hostnames)-1))
139 for idx in $(seq 0 "$NODE_MAX_ID"); do
140 NODE_IP=$(get_host_pxe_ip "nodes[${idx}]")
142 # shellcheck disable=SC2087
143 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
144 ssh -o StrictHostKeyChecking=no root@${NODE_IP} \
145 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh
150 # k8s Provisioning (currently BMRA)
152 # shellcheck disable=SC2087
153 ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << EOF
155 if ! command -v docker; then
156 curl -fsSL https://get.docker.com/ | sh
157 printf "Waiting for docker service..."
158 until sudo docker info; do
163 if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then
164 git clone --recurse-submodules --depth 1 https://github.com/intel/container-experience-kits.git -b v1.4.1 ${PROJECT_ROOT}/container-experience-kits/
165 cp -r ${PROJECT_ROOT}/container-experience-kits/examples/group_vars ${PROJECT_ROOT}/container-experience-kits/
166 #TODO Remove this once the reported issue is fixed in the next BMRA Release
167 sed -i '/\openshift/a \ extra_args: --ignore-installed PyYAML' \
168 ${PROJECT_ROOT}/container-experience-kits/roles/net-attach-defs-create/tasks/main.yml
170 cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini \
171 ${PROJECT_ROOT}/container-experience-kits/
172 cp ${PROJECT_ROOT}/${INSTALLER}/{all.yml,kube-node.yml} \
173 ${PROJECT_ROOT}/container-experience-kits/group_vars/
174 sudo docker run --rm \
175 -e ANSIBLE_CONFIG=/bmra/ansible.cfg \
176 -v ${PROJECT_ROOT}/container-experience-kits:/bmra \
177 -v ~/.ssh/:/root/.ssh/ rihabbanday/bmra-install:centos \
178 ansible-playbook -i /bmra/inventory.ini /bmra/playbooks/cluster.yml
182 # Executes a specific Ansible playbook
184 ansible_cmd="$(command -v ansible-playbook)"
185 ansible_cmd+=" -i $CURRENTPATH/inventory/localhost.ini"
186 ansible_cmd+=" -e ansible_python_interpreter=$(command -v python)"
187 if [ "${DEBUG:-false}" == "true" ]; then
190 eval "$ansible_cmd $CURRENTPATH/playbooks/${1}.yaml"