instack-undercloud/scripts/instack-install-undercloud
2015-05-11 18:30:45 +02:00

171 lines
6.3 KiB
Bash
Executable File

#!/bin/bash
set -eu
mkdir -p ~/.instack
LOGFILE=~/.instack/install-undercloud.log
exec > >(tee $LOGFILE)
exec 2>&1
echo "Running $0"
echo "Checking for a FQDN hostname..."
detected_static_hostname=$(sudo hostnamectl --static)
echo "static hostname detected as...$detected_static_hostname"
detected_transient_hostname=$(sudo hostnamectl --transient)
echo "transient hostname detected as...$detected_transient_hostname"
echo "\$HOSTNAME detected as...$HOSTNAME"
if [ ! "$detected_static_hostname" = "$detected_transient_hostname" ]; then
echo "static hostname does not match transient hostname"
echo "Use hostnamectl to set matching hostnames."
exit 1
fi
if [ ! "$detected_static_hostname" = "$HOSTNAME" ]; then
echo "static hostname does not match \$HOSTNAME"
echo "Set \$HOSTNAME to match or relogin so $HOSTNAME is redefined."
exit 1
fi
if ! grep -E "\s+$detected_static_hostname(\s|$)+" /etc/hosts; then
echo "static hostname not set in /etc/hosts"
echo "Please add a line to /etc/hosts for the static hostname."
exit 1
fi
# Attempt to be smart about detecting the path to the json files.
JSONFILEDIR=/usr/share/instack-undercloud/json-files
if [ ! -d "$JSONFILEDIR" ]; then
JSONFILEDIR=$(dirname $0)/../json-files
fi
if $(grep -Eqs 'Red Hat Enterprise Linux' /etc/redhat-release); then
export NODE_DIST=${NODE_DIST:-rhel7}
export JSONFILE=${JSONFILE:-$JSONFILEDIR/rhel-7-undercloud-packages.json}
export REG_METHOD=disable
export REG_HALT_UNREGISTER=1
elif $(grep -Eqs 'CentOS' /etc/redhat-release); then
export NODE_DIST=${NODE_DIST:-centos7}
export JSONFILE=${JSONFILE:-$JSONFILEDIR/centos-7-undercloud-packages.json}
elif $(grep -Eqs 'Fedora' /etc/redhat-release); then
export NODE_DIST=${NODE_DIST:-fedora}
echo "Fedora not currently supported"
exit 1
else
echo "Could not detect distritubion from /etc/redhat-release!"
exit 1
fi
# Attempt to be smart about detecting the patch to the instack-undercloud
# elements
INSTACKUNDERCLOUDELEMENTS=/usr/share/instack-undercloud
if [ ! -d $INSTACKUNDERCLOUDELEMENTS ]; then
INSTACKUNDERCLOUDELEMENTS=$(dirname $0)/../elements
fi
TRIPLEOPUPPETELEMENTS=/usr/share/tripleo-puppet-elements
if [ ! -d $TRIPLEOPUPPETELEMENTS ]; then
# Assume it's checked out in the current directory
TRIPLEOPUPPETELEMENTS=$PWD/tripleo-puppet-elements/elements
fi
export ELEMENTS_PATH=${ELEMENTS_PATH:-"\
$TRIPLEOPUPPETELEMENTS:\
$INSTACKUNDERCLOUDELEMENTS:\
/usr/share/tripleo-image-elements:\
/usr/share/diskimage-builder/elements"}
echo "Sourcing answers file from instack.answers..."
source ~/instack.answers
# Munge up LOCAL_IP.
export PUBLIC_INTERFACE_IP="$LOCAL_IP"
export LOCAL_IP="${LOCAL_IP%/*}"
export IMAGE_PATH
export LOCAL_INTERFACE
export MASQUERADE_NETWORK
export DHCP_START
export DHCP_END
export NETWORK_CIDR
export NETWORK_GATEWAY
export DISCOVERY_INTERFACE
export DISCOVERY_IPRANGE
export DISCOVERY_RUNBENCH
export UNDERCLOUD_DEBUG
# Reuse any existing defined passwords. This is important since any users
# defined in Keystone already have passwords set. So we don't want to generate
# new ones that end up as values in configuration files.
if sudo bash -c '[[ -f /root/tripleo-undercloud-passwords ]]'; then
source <(sudo cat /root/tripleo-undercloud-passwords)
fi
export UNDERCLOUD_HEAT_STACK_DOMAIN_ADMIN_PASSWORD=${UNDERCLOUD_HEAT_STACK_DOMAIN_ADMIN_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_RABBIT_COOKIE=${UNDERCLOUD_RABBIT_COOKIE:-$(tripleo os-make-password)}
export UNDERCLOUD_RABBIT_PASSWORD=${UNDERCLOUD_RABBIT_PASSWORD:-guest}
export UNDERCLOUD_RABBIT_USERNAME=${UNDERCLOUD_RABBIT_USERNAME:-guest}
export UNDERCLOUD_SWIFT_HASH_SUFFIX=${UNDERCLOUD_SWIFT_HASH_SUFFIX:-$(tripleo os-make-password)}
export UNDERCLOUD_ADMIN_PASSWORD=${UNDERCLOUD_ADMIN_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_ADMIN_TOKEN=${UNDERCLOUD_ADMIN_TOKEN:-$(tripleo os-make-password)}
export UNDERCLOUD_CEILOMETER_METERING_SECRET=${UNDERCLOUD_CEILOMETER_METERING_SECRET:-$(tripleo os-make-password)}
export UNDERCLOUD_CEILOMETER_PASSWORD=${UNDERCLOUD_CEILOMETER_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_CEILOMETER_SNMPD_PASSWORD=${UNDERCLOUD_CEILOMETER_SNMPD_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_CEILOMETER_SNMPD_USER=${UNDERCLOUD_CEILOMETER_SNMPD_USER:-$(tripleo os-make-password)}
export UNDERCLOUD_GLANCE_PASSWORD=${UNDERCLOUD_GLANCE_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_HEAT_PASSWORD=${UNDERCLOUD_HEAT_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_HORIZON_SECRET_KEY=${UNDERCLOUD_HORIZON_SECRET_KEY:-$(tripleo os-make-password)}
export UNDERCLOUD_IRONIC_PASSWORD=${UNDERCLOUD_IRONIC_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_NEUTRON_PASSWORD=${UNDERCLOUD_NEUTRON_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_NOVA_PASSWORD=${UNDERCLOUD_NOVA_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_SWIFT_PASSWORD=${UNDERCLOUD_SWIFT_PASSWORD:-$(tripleo os-make-password)}
export UNDERCLOUD_TUSKAR_PASSWORD=${UNDERCLOUD_TUSKAR_PASSWORD:-$(tripleo os-make-password)}
sudo -E instack \
-p $ELEMENTS_PATH \
-j $JSONFILE
RUN_ORC=${RUN_ORC:-"1"}
export INSTACK_ROOT=${INSTACK_ROOT:-""}
if [ "$RUN_ORC" = "1" ]; then
sudo INSTACK_ROOT=$INSTACK_ROOT IMAGE_PATH=$IMAGE_PATH os-refresh-config
# generate ssh authentication keys if they don't exist
if [ ! -f ~/.ssh/id_rsa ]; then
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
fi
source <(sudo cat /root/stackrc)
if ! nova keypair-show default 2>/dev/null; then
tripleo user-config
fi
fi
# This is owned by root, which can break later image builds as a regular user
sudo rm -f /tmp/svc-map-services
export COMPLETION_MESSAGE=${COMPLETION_MESSAGE:-"\
#############################################################################
instack-install-undercloud complete.
The file containing this installation's passwords is at
/root/tripleo-undercloud-passwords.
There is also a stackrc file at /root/stackrc.
These files are needed to interact with the OpenStack services, and should be
secured. For convenience, they can be copied to the current directory:
sudo cp /root/tripleo-undercloud-passwords .
sudo chown $USER: tripleo-undercloud-passwords
sudo cp /root/stackrc .
sudo chown $USER: stackrc
#############################################################################"}
echo "$COMPLETION_MESSAGE"