Add compute node deployment script

This commit adds pretty simple script which makes possible to simply
deploy new compute node with just single command. It also allows
deployer to define pre and post tasks to be runned in case some
customization is needed.

Change-Id: I00031eb7e7d6cd9b9fe86b5c649ddd6f64630ffe
This commit is contained in:
Dmitriy Rabotyagov 2020-02-07 14:45:10 +02:00 committed by Dmitriy Rabotyagov (noonedeadpunk)
parent 8281d664cb
commit bb01eedcda
2 changed files with 102 additions and 0 deletions

View File

@ -103,6 +103,20 @@ cluster.
# ansible nova_all -m setup -a 'filter=ansible_local gather_subset="!all"'
# openstack-ansible setup-openstack.yml --limit localhost,NEW_HOST_NAME
Alternatively you can try using new compute nodes deployment script
``/opt/openstack-ansible/scripts/add-compute.sh``.
You can provide this script with extra tasks that will be executed
before or right after OSA roles. To do so you should set environment
variables ``PRE_OSA_TASKS`` or ``POST_OSA_TASKS`` with plays to run devided
with semicolon:
.. code-block:: shell-session
# export POST_OSA_TASKS="/opt/custom/setup.yml --limit HOST_NAME;/opt/custom/tasks.yml --tags deploy"
# /opt/openstack-ansible/scripts/add-compute.sh HOST_NAME,HOST_NAME_2
Test new compute nodes
~~~~~~~~~~~~~~~~~~~~~~

88
scripts/add-compute.sh Executable file
View File

@ -0,0 +1,88 @@
#!/usr/bin/env bash
# Copyright 2020, VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export OSA_REPO_PATH=${OSA_REPO_PATH:-"/opt/openstack-ansible"}
export HOSTS=${1:-""}
function define_tasks {
if [[ ! -z ${PRE_OSA_TASKS} ]]; then
if [ "${BASH_VERSINFO[0]}" -ge 4 ] && [ "${BASH_VERSINFO[1]}" -ge 4 ]; then
readarray -td";" PRE_TASKS <<<"$PRE_OSA_TASKS"
else
readarray -t PRE_TASKS <<<"$(echo "$PRE_OSA_TASKS" | tr ';' '\n')"
fi
for i in ${!PRE_TASKS[@]}; do
RUN_TASKS+=("${PRE_TASKS[$i]}")
done
fi
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/setup-hosts.yml --limit ${HOSTS}")
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/setup-openstack.yml --limit ${HOSTS}")
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/openstack-hosts-setup.yml --tags openstack_hosts-config")
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/unbound-install.yml --tags unbound-config")
RUN_TASKS+=("${OSA_REPO_PATH}/playbooks/os-nova-install.yml --tags nova-key --limit nova_compute")
if [[ ! -z ${POST_OSA_TASKS} ]]; then
if [ "${BASH_VERSINFO[0]}" -ge 4 ] && [ "${BASH_VERSINFO[1]}" -ge 4 ]; then
readarray -td";" POST_TASKS <<<"$POST_OSA_TASKS"
else
readarray -t POST_TASKS <<<"$(echo "$POST_OSA_TASKS" | tr ';' '\n')"
fi
for i in ${!POST_TASKS[@]}; do
RUN_TASKS+=("${POST_TASKS[$i]}")
done
fi
}
function run_tasks {
set +e
for item in ${!RUN_TASKS[@]}; do
eval "echo openstack-ansible ${RUN_TASKS[$item]}"
playbook_status="$?"
if [[ ${playbook_status} -gt 0 ]]; then
echo "*********************** failure ************************"
echo "The compute deployment script has encountered a failure."
echo "Failed on task \"${RUN_TASKS[$item]}\" with status $playbook_status"
echo "Re-run the script, or execute tasks manually:"
for item in $(seq $item $((${#RUN_TASKS[@]} - 1))); do
if [ -n "${RUN_TASKS[$item]}" ]; then
echo "openstack-ansible ${RUN_TASKS[$item]}"
fi
done
echo "*********************** failure ************************"
exit ${playbook_status}
# else
# echo "task ${RUN_TASKS[$item]} ran successfully"
fi
done
set -e
}
function main {
if [[ -z ${HOSTS} ]]; then
echo "Hosts to setup are not provided"
exit 1
elif [[ ! -d ${OSA_REPO_PATH} ]]; then
echo "OSA repo is not found: ${OSA_REPO_PATH}. Define OSA_REPO_PATH to set another directory"
exit 1
fi
define_tasks
run_tasks
}
main