Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 1 | #!/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 | |
| 20 | set -o errexit |
| 21 | set -o nounset |
| 22 | set -o pipefail |
| 23 | |
Fatih Degirmenci | 956f8b6 | 2019-12-16 10:53:15 +0100 | [diff] [blame] | 24 | PROVISIONER_ROOT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" |
Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 25 | export ANSIBLE_ROLES_PATH="$HOME/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:${ENGINE_PATH}/engine/playbooks/roles:${ENGINE_CACHE}/repos/bifrost/playbooks/roles" |
| 26 | export ANSIBLE_LIBRARY="$HOME/.ansible/plugins/modules:/usr/share/ansible/plugins/modules:${ENGINE_CACHE}/repos/bifrost/playbooks/library" |
| 27 | |
Fatih Degirmenci | 956f8b6 | 2019-12-16 10:53:15 +0100 | [diff] [blame] | 28 | # TODO: ignoring SC2015 for the timebeing so we don't break things |
| 29 | # shellcheck disable=SC2015 |
Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 30 | # set the BAREMETAL variable |
Fatih Degirmenci | ef0b16f | 2020-01-08 23:53:05 +0000 | [diff] [blame^] | 31 | grep -o "vendor.*" "${ENGINE_PATH}/engine/inventory/group_vars/all/pdf.yaml" | grep -q libvirt && export BAREMETAL=false || export BAREMETAL=true |
Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 32 | |
| 33 | # create libvirt resources if not baremetal, install and configure bifrost |
| 34 | echo "Info: Prepare nodes, configure bifrost and create bifrost inventory" |
| 35 | echo "-------------------------------------------------------------------------" |
Fatih Degirmenci | 956f8b6 | 2019-12-16 10:53:15 +0100 | [diff] [blame] | 36 | cd "${ENGINE_PATH}" |
Sriram Yagnaraman | 56d6318 | 2019-12-25 01:40:00 +0000 | [diff] [blame] | 37 | ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \ |
Fatih Degirmenci | ef0b16f | 2020-01-08 23:53:05 +0000 | [diff] [blame^] | 38 | -i "${ENGINE_PATH}/engine/inventory/localhost.ini" \ |
| 39 | -e baremetal="${BAREMETAL}" \ |
| 40 | "${PROVISIONER_ROOT_DIR}/playbooks/main.yml" |
Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 41 | echo "-------------------------------------------------------------------------" |
| 42 | |
Vamsi Savaram | 6580c93 | 2019-08-06 12:42:02 +0000 | [diff] [blame] | 43 | # 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 Degirmenci | 956f8b6 | 2019-12-16 10:53:15 +0100 | [diff] [blame] | 46 | export VENV="${ENGINE_VENV}" |
Vamsi Savaram | 6580c93 | 2019-08-06 12:42:02 +0000 | [diff] [blame] | 47 | # 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 Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 52 | # install bifrost and enroll & deploy nodes |
| 53 | echo "Info: Install bifrost" |
| 54 | echo "-------------------------------------------------------------------------" |
Fatih Degirmenci | 956f8b6 | 2019-12-16 10:53:15 +0100 | [diff] [blame] | 55 | cd "${ENGINE_CACHE}/repos/bifrost/playbooks" |
Sriram Yagnaraman | 56d6318 | 2019-12-25 01:40:00 +0000 | [diff] [blame] | 56 | ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \ |
Fatih Degirmenci | ef0b16f | 2020-01-08 23:53:05 +0000 | [diff] [blame^] | 57 | -i inventory/target \ |
| 58 | -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \ |
| 59 | bifrost-install.yml |
Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 60 | echo "-------------------------------------------------------------------------" |
| 61 | |
| 62 | echo "Info: Enroll and deploy nodes using bifrost" |
| 63 | echo "-------------------------------------------------------------------------" |
Fatih Degirmenci | 956f8b6 | 2019-12-16 10:53:15 +0100 | [diff] [blame] | 64 | cd "${ENGINE_CACHE}/repos/bifrost/playbooks" |
Sriram Yagnaraman | 56d6318 | 2019-12-25 01:40:00 +0000 | [diff] [blame] | 65 | ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \ |
Fatih Degirmenci | ef0b16f | 2020-01-08 23:53:05 +0000 | [diff] [blame^] | 66 | -i inventory/bifrost_inventory.py \ |
| 67 | -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \ |
| 68 | bifrost-enroll-deploy.yml |
Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 69 | echo "-------------------------------------------------------------------------" |
| 70 | |
Fatih Degirmenci | ef0b16f | 2020-01-08 23:53:05 +0000 | [diff] [blame^] | 71 | # 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 Degirmenci | a537fd1 | 2019-06-12 16:21:11 +0200 | [diff] [blame] | 75 | echo "Info: Generate Ansible inventory" |
| 76 | echo "-------------------------------------------------------------------------" |
Fatih Degirmenci | ef0b16f | 2020-01-08 23:53:05 +0000 | [diff] [blame^] | 77 | cd "${ENGINE_PATH}" |
Sriram Yagnaraman | 56d6318 | 2019-12-25 01:40:00 +0000 | [diff] [blame] | 78 | ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \ |
Fatih Degirmenci | ef0b16f | 2020-01-08 23:53:05 +0000 | [diff] [blame^] | 79 | -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 Degirmenci | a537fd1 | 2019-06-12 16:21:11 +0200 | [diff] [blame] | 82 | |
| 83 | echo "-------------------------------------------------------------------------" |
Fatih Degirmenci | 50b146b | 2019-05-10 14:11:57 +0200 | [diff] [blame] | 84 | echo "Info: Nodes are provisioned using bifrost!" |
| 85 | echo "-------------------------------------------------------------------------" |
| 86 | |
| 87 | # vim: set ts=2 sw=2 expandtab: |