-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathundercloud.sh
executable file
·144 lines (124 loc) · 5.81 KB
/
undercloud.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018,2023
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o nounset
set -o pipefail
set -o errexit
if [[ ${OS_DEBUG:-false} == "true" ]]; then
export PKG_DEBUG=true
set -o xtrace
fi
source defaults.env
source commons.sh
# shellcheck disable=SC1091
source /etc/os-release || source /usr/lib/os-release
function _setup_proxy {
if [ -n "${HTTP_PROXY-}" ]; then
sed -i "s|^container_http_proxy: .*$|container_http_proxy: \"${HTTP_PROXY}\"|g" ~/.local/share/kolla-ansible/ansible/group_vars/all.yml
echo "[Service]" | sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf
echo "Environment=\"HTTP_PROXY=$HTTP_PROXY\"" | sudo tee --append /etc/systemd/system/docker.service.d/http-proxy.conf
fi
if [ -n "${HTTPS_PROXY-}" ]; then
sed -i "s|^container_https_proxy: .*$|container_https_proxy: \"${HTTPS_PROXY}\"|g" ~/.local/share/kolla-ansible/ansible/group_vars/all.yml
echo "[Service]" | sudo tee /etc/systemd/system/docker.service.d/https-proxy.conf
echo "Environment=\"HTTPS_PROXY=$HTTPS_PROXY\"" | sudo tee --append /etc/systemd/system/docker.service.d/https-proxy.conf
fi
if [ -n "${NO_PROXY-}" ]; then
sed -i "s|^container_no_proxy: .*$|container_no_proxy: \"${NO_PROXY}\"|g" ~/.local/share/kolla-ansible/ansible/group_vars/all.yml
echo "[Service]" | sudo tee /etc/systemd/system/docker.service.d/no-proxy.conf
echo "Environment=\"NO_PROXY=$NO_PROXY\"" | sudo tee --append /etc/systemd/system/docker.service.d/no-proxy.conf
fi
}
function _get_kolla_actions {
local kolla_ansible_version="$1"
local kolla_deploy_profile="${2:-$OS_KOLLA_DEPLOY_PROFILE}"
kolla_actions=(bootstrap-servers)
# Install Ansible Galaxy dependencies (Yoga release onwards)
if vercmp "$kolla_ansible_version" '>=' '14'; then
kolla_actions=(install-deps "${kolla_actions[@]}")
fi
if [ "${kolla_deploy_profile}" == "complete" ]; then
kolla_actions=("${kolla_actions[@]}" prechecks pull)
fi
kolla_actions=("${kolla_actions[@]}" deploy)
if [ "${kolla_deploy_profile}" == "complete" ] && vercmp "$kolla_ansible_version" '<' '15'; then
# NOTE: Smoke tests have been removed in Zed release (https://github.com/openstack/kolla-ansible/commit/591f366ed736977664e899bd834e363191a9472d#diff-707286526f137598948e03470854d542446836f5dd83cbfcb30caab67bb6c7bb)
kolla_actions=("${kolla_actions[@]}" check)
fi
kolla_actions=("${kolla_actions[@]}" post-deploy)
echo "${kolla_actions[@]}"
}
function _remove_conflicting_python_pkgs {
case ${ID,,} in
ubuntu | debian)
sanity_pkgs=""
for pkg in python-cryptography python3-cryptography python3-distro-info python3-debian python3-openssl python3-docker python3-urllib3; do
if sudo dpkg -l "$pkg" >/dev/null; then
sanity_pkgs+="$pkg "
fi
done
eval "sudo apt remove -y $sanity_pkgs"
;;
esac
}
function _install_deps {
_remove_conflicting_python_pkgs
# Install dependencies
curl -fsSL http://bit.ly/install_bin | PKG_BINDEP_PROFILE=undercloud PKG_COMMANDS_LIST="yq" PKG_UPDATE=true bash
# Install Kolla-Ansible dependencies
sudo ln -s "$(command -v pip3)" /usr/bin/pip3 || :
pip install --ignore-installed --no-warn-script-location --requirement "requirements/${OPENSTACK_RELEASE}/${ID,,}_${VERSION_ID%.*}.txt"
# PEP 370 -- Per user site-packages directory
[[ $PATH != *.local/bin* ]] && export PATH=$PATH:$HOME/.local/bin
# https://review.opendev.org/c/openstack/kolla-ansible/+/584427/17/ansible/roles/rabbitmq/templates/rabbitmq-env.conf.j2#6
sudo find / -name rabbitmq-env.conf.j2 -exec sed -i '/export ERL_EPMD_ADDRESS/d' {} \;
}
function _cleanup_docker_services {
# Remove docker source list to avoid update conflicts
[[ $PATH != *.local/bin* ]] && export PATH=$PATH:$HOME/.local/bin
ansible control -i "${OS_INVENTORY_FILE:-./samples/aio/hosts.ini}" -m file \
-a 'path=/etc/apt/sources.list.d/docker.list state=absent' -b \
-e "ansible_user=$USER"
sudo rm -f /etc/docker/daemon.json
}
function _run_kolla_ansible {
# PEP 370 -- Per user site-packages directory
[[ $PATH != *.local/bin* ]] && export PATH=$PATH:$HOME/.local/bin
kolla-genpwd
kolla_ansible_version="$(pip freeze | grep kolla-ansible | sed 's/^.*=//')"
# shellcheck disable=SC2046
run_kolla_actions $(_get_kolla_actions "$kolla_ansible_version")
sudo chown "$USER" /etc/kolla/admin-openrc.sh
# shellcheck disable=SC2002
cat /etc/kolla/admin-openrc.sh | sudo tee --append /etc/environment
}
function main {
sudo touch /etc/timezone
_start=$(date +%s)
trap 'printf "Provisioning process: %s secs\n" "$(($(date +%s)-_start))"' EXIT
_install_deps
sudo mkdir -p /etc/{kolla,ansible,systemd/system/docker.service.d}
# Setup configuration values
if [ "${OS_ENABLE_LOCAL_REGISTRY:-false}" == "true" ]; then
export OS_KOLLA_DOCKER_REGISTRY="${DOCKER_REGISTRY_IP:-127.0.0.1}:${DOCKER_REGISTRY_PORT:-5000}"
export OS_KOLLA_DOCKER_REGISTRY_INSECURE="yes"
export OS_KOLLA_DOCKER_NAMESPACE="kolla"
fi
set_values
_setup_proxy
setup_ansible
_cleanup_docker_services
_run_kolla_ansible
if groups | grep -q docker && (! getent group docker | grep -q "$USER"); then
sudo usermod -aG docker "$USER"
fi
}
if [[ ${__name__:-"__main__"} == "__main__" ]]; then
main
fi