blob: e45a25d345e32bb9b87bc0238b865dc45ff6f212 [file] [log] [blame]
Fatih Degirmenci50b146b2019-05-10 14:11:57 +02001#!/bin/bash
2# ============LICENSE_START=======================================================
3# Copyright (C) 2019 The Nordix Foundation. All rights reserved.
4# ================================================================================
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# SPDX-License-Identifier: Apache-2.0
18# ============LICENSE_END=========================================================
19
20set -o errexit
21set -o nounset
22set -o pipefail
23
Fatih Degirmenci956f8b62019-12-16 10:53:15 +010024PROVISIONER_ROOT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020025export ANSIBLE_ROLES_PATH="$HOME/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:${ENGINE_PATH}/engine/playbooks/roles:${ENGINE_CACHE}/repos/bifrost/playbooks/roles"
26export ANSIBLE_LIBRARY="$HOME/.ansible/plugins/modules:/usr/share/ansible/plugins/modules:${ENGINE_CACHE}/repos/bifrost/playbooks/library"
27
Fatih Degirmenci956f8b62019-12-16 10:53:15 +010028# TODO: ignoring SC2015 for the timebeing so we don't break things
29# shellcheck disable=SC2015
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020030# set the BAREMETAL variable
Fatih Degirmencief0b16f2020-01-08 23:53:05 +000031grep -o "vendor.*" "${ENGINE_PATH}/engine/inventory/group_vars/all/pdf.yaml" | grep -q libvirt && export BAREMETAL=false || export BAREMETAL=true
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020032
33# create libvirt resources if not baremetal, install and configure bifrost
34echo "Info: Prepare nodes, configure bifrost and create bifrost inventory"
35echo "-------------------------------------------------------------------------"
Fatih Degirmenci956f8b62019-12-16 10:53:15 +010036cd "${ENGINE_PATH}"
Sriram Yagnaraman56d63182019-12-25 01:40:00 +000037ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
Fatih Degirmencief0b16f2020-01-08 23:53:05 +000038 -i "${ENGINE_PATH}/engine/inventory/localhost.ini" \
39 -e baremetal="${BAREMETAL}" \
40 "${PROVISIONER_ROOT_DIR}/playbooks/main.yml"
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020041echo "-------------------------------------------------------------------------"
42
Vamsi Savaram6580c932019-08-06 12:42:02 +000043# Bifrost looks at environment variable VENV to see if it needs to use
44# virtual environment.
45# See: https://docs.openstack.org/bifrost/latest/install/virtualenv.html
Fatih Degirmenci956f8b62019-12-16 10:53:15 +010046export VENV="${ENGINE_VENV}"
Vamsi Savaram6580c932019-08-06 12:42:02 +000047# In bifrost inventory/target and inventory/localhost are defined as:
48# 127.0.0.1 ansible_connection=local
49# Hence ansible_python_interpreter needs to be set for localhost
50# tasks to force ansible to use python from virtual environment.
51
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020052# install bifrost and enroll & deploy nodes
53echo "Info: Install bifrost"
54echo "-------------------------------------------------------------------------"
Fatih Degirmenci956f8b62019-12-16 10:53:15 +010055cd "${ENGINE_CACHE}/repos/bifrost/playbooks"
Sriram Yagnaraman56d63182019-12-25 01:40:00 +000056ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
Fatih Degirmencief0b16f2020-01-08 23:53:05 +000057 -i inventory/target \
58 -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \
59 bifrost-install.yml
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020060echo "-------------------------------------------------------------------------"
61
62echo "Info: Enroll and deploy nodes using bifrost"
63echo "-------------------------------------------------------------------------"
Fatih Degirmenci956f8b62019-12-16 10:53:15 +010064cd "${ENGINE_CACHE}/repos/bifrost/playbooks"
Sriram Yagnaraman56d63182019-12-25 01:40:00 +000065ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
Fatih Degirmencief0b16f2020-01-08 23:53:05 +000066 -i inventory/bifrost_inventory.py \
67 -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \
68 bifrost-enroll-deploy.yml
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020069echo "-------------------------------------------------------------------------"
70
Fatih Degirmencief0b16f2020-01-08 23:53:05 +000071# copy bifrost_inventory.py to engine inventory folder so we can access to group_vars
72/bin/cp -f "${ENGINE_CACHE}/repos/bifrost/playbooks/inventory/bifrost_inventory.py" \
73 "${ENGINE_PATH}/engine/inventory/bifrost_inventory.py"
74
Fatih Degirmencia537fd12019-06-12 16:21:11 +020075echo "Info: Generate Ansible inventory"
76echo "-------------------------------------------------------------------------"
Fatih Degirmencief0b16f2020-01-08 23:53:05 +000077cd "${ENGINE_PATH}"
Sriram Yagnaraman56d63182019-12-25 01:40:00 +000078ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
Fatih Degirmencief0b16f2020-01-08 23:53:05 +000079 -i "${ENGINE_PATH}/engine/inventory/bifrost_inventory.py" \
80 --ssh-extra-args " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
81 "${PROVISIONER_ROOT_DIR}/playbooks/generate-inventory.yml"
Fatih Degirmencia537fd12019-06-12 16:21:11 +020082
83echo "-------------------------------------------------------------------------"
Fatih Degirmenci50b146b2019-05-10 14:11:57 +020084echo "Info: Nodes are provisioned using bifrost!"
85echo "-------------------------------------------------------------------------"
86
87# vim: set ts=2 sw=2 expandtab: