Created
August 31, 2015 14:36
-
-
Save hassenius/afded9c93bca61ec6ca2 to your computer and use it in GitHub Desktop.
Bash script to install single node OpenStack Heat with mariadb and rabbitmq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
################################################################################ | |
# install-heat.sh | |
# ©Copyright IBM Corporation 2015. | |
# | |
# Bash script to install single node OpenStack Heat with mariadb and rabbitmq | |
# LICENSE: MIT (http://opensource.org/licenses/MIT) | |
################################################################################ | |
echo "Script loosely based on https://github.com/sushilkm/heat-standalone/blob/master/install-heat" | |
echo | |
set -e | |
if [ -z "$OS_AUTH_URL" ] | |
then | |
echo "Cannot find openstack authentication url in environment variables" | |
echo "Please source your openstack.rc file" | |
exit 1 | |
else | |
AUTH_URI=$(echo $OS_AUTH_URL | cut -d/ -f1,2,3) | |
fi | |
if [ -e "localrc" ] | |
then | |
echo " * Loading local configuration from 'localrc'..." | |
source localrc | |
else | |
echo | |
echo | |
echo "Enter desired configuration values. Hit enter to accept defaults. All variables have defaults except passwords" | |
echo | |
echo -n " * Region to deploy in (RegionOne): " | |
read -e REGION | |
echo -n " * Heat admin user (heat): " | |
read -e HEAT_ADMIN_USER | |
while [[ -z "$HEAT_ADMIN_PASSWORD" ]] | |
do | |
echo -n " * Password to set for heat admin user: " | |
read -e HEAT_ADMIN_PASSWORD | |
done | |
while [[ -z "$DATABASE_PASSWORD" ]] | |
do | |
echo -n " * Mysql password to set for root user: " | |
read -e DATABASE_PASSWORD | |
done | |
while [[ -z "$HEAT_DATABASE_PASSWORD" ]] | |
do | |
echo -n " * Mysql password to set for heat user: " | |
read -e HEAT_DATABASE_PASSWORD | |
done | |
echo -n " * Enter RabbitMQ username to create for heat (openstack): " | |
read -e RABBITMQ_USER | |
while [[ -z "$RABBITMQ_PASSWORD" ]] | |
do | |
echo -n " * Password to set for user in RabbitMQ: " | |
read -e RABBITMQ_PASSWORD | |
done | |
read -r -p " * Would you like to update the keystone service catalog with the new heat endpoint? [y/N] " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
UPDATE_KEYSTONE_CATALOG=yes | |
;; | |
*) | |
echo "Keystone catalog will not automatically be updated. You can update it manually later" | |
UPDATE_KEYSTONE_CATALOG=no | |
;; | |
esac | |
# Set defaults | |
HEAT_ADMIN_USER=${HEAT_ADMIN_USER:-heat} | |
REGION=${REGION:-RegionOne} | |
RABBITMQ_USER=${RABBITMQ_USER:-openstack} | |
echo REGION=$REGION > localrc | |
echo AUTH_URI=$AUTH_URI >> localrc | |
echo HEAT_ADMIN_USER=$HEAT_ADMIN_USER >> localrc | |
echo HEAT_ADMIN_PASSWORD=$HEAT_ADMIN_PASSWORD >> localrc | |
echo DATABASE_PASSWORD=$DATABASE_PASSWORD >> localrc | |
echo HEAT_DATABASE_PASSWORD=$HEAT_DATABASE_PASSWORD >> localrc | |
echo RABBITMQ_USER=$RABBITMQ_USER >> localrc | |
echo RABBITMQ_PASSWORD=$RABBITMQ_PASSWORD >> localrc | |
echo UPDATE_KEYSTONE_CATALOG=no >> localrc | |
echo "Your choices have been written to localrc for reference..." | |
echo "If you need to rerun this script the values will automatically be read from this file" | |
fi | |
echo " * Region will be set to '${REGION}'..." | |
echo " * Auth URL will be set to '${AUTH_URI}'..." | |
echo " * Heat Admin user will be set to '${HEAT_ADMIN_USER}'..." | |
echo " * Heat Admin Password will be set to '${HEAT_ADMIN_PASSWORD}'..." | |
echo " * Mysql root password will be set to '${DATABASE_PASSWORD}'..." | |
echo " * Mysql password for heat user will be set to '${HEAT_DATABASE_PASSWORD}'..." | |
echo " * RABBITMQ user will be set to '${RABBITMQ_USER}'..." | |
echo " * RABBITMQ password will be set to '${RABBITMQ_PASSWORD}'..." | |
sleep 3 | |
echo | |
echo "=== Installing Heat ===" | |
echo | |
echo " * Fetching necessary information..." | |
PUBLIC_IP="$(curl http://169.254.169.254/latest/meta-data/public-ipv4 2> /dev/null)" | |
echo " * Preseeding mysql server configuration..." | |
cat << MYSQL_PRESEED | sudo debconf-set-selections | |
mysql-server mysql-server/root_password password ${DATABASE_PASSWORD} | |
mysql-server mysql-server/root_password_again password ${DATABASE_PASSWORD} | |
mysql-server mysql-server/start_on_boot boolean true | |
MYSQL_PRESEED | |
echo " * Installing prerequisite packages including rabbitmq-server and mysql-server..." | |
sudo apt-get --quiet update | |
sudo apt-get --quiet --assume-yes install \ | |
mariadb-server \ | |
python-mysqldb \ | |
ntp \ | |
rabbitmq-server \ | |
python-pip | |
echo " * Updating rabbitmq password and permissions..." | |
if [[ $( sudo rabbitmqctl list_users | grep ${RABBITMQ_USER} ) ]] | |
then | |
echo "Warning: user ${RABBITMQ_USER} already exists. will still update password and permissions, but something may have gone wrong" | |
sudo rabbitmqctl change_password ${RABBITMQ_USER} "${RABBITMQ_PASSWORD}" | |
sudo rabbitmqctl set_permissions ${RABBITMQ_USER} ".*" ".*" ".*" | |
else | |
sudo rabbitmqctl add_user ${RABBITMQ_USER} "${RABBITMQ_PASSWORD}" | |
sudo rabbitmqctl set_permissions ${RABBITMQ_USER} ".*" ".*" ".*" | |
fi | |
echo " * Setting up heat database..." | |
if [[ $(echo "show databases;" | mysql -u root --password=${DATABASE_PASSWORD} | grep heat) ]] | |
then | |
echo "Warning: Database heat already exists. This should be fine if you're rerunning the script with the same localrc file. Continuing'" | |
else | |
mysql -u root --password=${DATABASE_PASSWORD} <<EOF | |
CREATE DATABASE heat; | |
GRANT ALL PRIVILEGES ON heat.* TO 'heat'@'localhost' IDENTIFIED BY '${HEAT_DATABASE_PASSWORD}'; | |
quit | |
EOF | |
fi | |
echo " * Installing openstack-clients..." | |
sudo apt-get --quiet --assume-yes install python-openstackclient | |
sudo pip install pyopenssl ndg-httpsclient pyasn1 | |
echo " * Installing heat..." | |
sudo apt-get --quiet --assume-yes install ubuntu-cloud-keyring | |
sudo sh -c 'echo "deb http://ubuntu-cloud.archive.canonical.com/ubuntu trusty-updates/juno main" > /etc/apt/sources.list.d/cloudarchive-juno.list' | |
sudo apt-get update && sudo apt-get --quiet --assume-yes dist-upgrade | |
sudo apt-get --quiet --assume-yes install heat-api heat-api-cfn heat-engine python-heatclient | |
echo " * Updating heat configuration files..." | |
orig_heatconf_owner=$(sudo stat -c '%U' /etc/heat/heat.conf) | |
sudo chown -R $(whoami) /etc/heat | |
cat > /etc/heat/heat.conf << EOF | |
[DEFAULT] | |
heat_metadata_server_url=http://${PUBLIC_IP}:8000 | |
heat_waitcondition_server_url=http://${PUBLIC_IP}:8000/v1/waitcondition | |
rpc_backend=rabbit | |
rabbit_host=localhost | |
rabbit_password=${RABBITMQ_PASSWORD} | |
rabbit_userid=${RABBITMQ_USER} | |
verbose=false | |
log_dir=/var/log/heat | |
[database] | |
connection=mysql://heat:${HEAT_DATABASE_PASSWORD}@localhost/heat | |
[keystone_authtoken] | |
auth_uri=${AUTH_URI} | |
identity_uri=${AUTH_URI} | |
admin_tenant_name=service | |
admin_user=${HEAT_ADMIN_USER} | |
admin_password=${HEAT_ADMIN_PASSWORD} | |
EOF | |
sudo chown -R $orig_heatconf_owner /etc/heat | |
echo " * Setting up heat database..." | |
sudo su -s /bin/sh -c "heat-manage db_sync" heat | |
echo " * Creating heat service user and roles..." | |
if [[ $(openstack user list | grep ${HEAT_ADMIN_USER}) ]] | |
then | |
echo "Warning: User ${HEAT_ADMIN_USER} already exists in keystone user list" | |
echo "Continuing, but something may have gone wrong" | |
else | |
keystone user-create --name ${HEAT_ADMIN_USER} --pass ${HEAT_ADMIN_PASSWORD} | |
keystone user-role-add --user ${HEAT_ADMIN_USER} --tenant service --role admin | |
fi | |
if [[ $(openstack role list | grep 'heat_stack_owner\|heat_stack_user') ]] | |
then | |
echo "Warning: role heat_stack_owner and/or heat_stack_user already exists." | |
echo "Continuing, but something may have gone wrong" | |
else | |
keystone role-create --name heat_stack_owner | |
keystone role-create --name heat_stack_user | |
fi | |
if [[ "$UPDATE_KEYSTONE_CATALOG" == "yes" ]] | |
then | |
echo " * Updating keystone service catalog..." | |
if [[ $(keystone catalog | grep orchestration) ]] | |
then | |
echo "Warning: Heat already exists in the keystone service registry." | |
echo "Continuing, but something may have gone wrong" | |
else | |
keystone service-create --name heat --type orchestration \ | |
--description "Orchestration" | |
keystone service-create --name heat-cfn --type cloudformation \ | |
--description "Orchestration" | |
keystone endpoint-create \ | |
--service-id $(keystone service-list | awk '/ orchestration / {print $2}') \ | |
--publicurl http://${PUBLIC_IP}:8004/v1/%\(tenant_id\)s \ | |
--internalurl http://${PUBLIC_IP}:8004/v1/%\(tenant_id\)s \ | |
--adminurl http://${PUBLIC_IP}:8004/v1/%\(tenant_id\)s \ | |
--region ${REGION} | |
keystone endpoint-create \ | |
--service-id $(keystone service-list | awk '/ cloudformation / {print $2}') \ | |
--publicurl http://${PUBLIC_IP}:8000/v1 \ | |
--internalurl http://${PUBLIC_IP}:8000/v1 \ | |
--adminurl http://${PUBLIC_IP}:8000/v1 \ | |
--region ${REGION} | |
fi | |
else | |
echo " * Keystone service catalog will not be updated at this point" | |
echo "You can update it later with the commands:" | |
echo "1. keystone service-create --name heat --type orchestration \ | |
--description 'Orchestration'" | |
echo "2. keystone service-create --name heat-cfn --type cloudformation \ | |
--description 'Orchestration'" | |
echo "3. keystone endpoint-create \ | |
--service-id $(keystone service-list | awk '/ orchestration / {print $2}') \ | |
--publicurl http://${PUBLIC_IP}:8004/v1/%\(tenant_id\)s \ | |
--internalurl http://${PUBLIC_IP}:8004/v1/%\(tenant_id\)s \ | |
--adminurl http://${PUBLIC_IP}:8004/v1/%\(tenant_id\)s \ | |
--region ${REGION}" | |
echo "4. keystone endpoint-create \ | |
--service-id $(keystone service-list | awk '/ cloudformation / {print $2}') \ | |
--publicurl http://${PUBLIC_IP}:8000/v1 \ | |
--internalurl http://${PUBLIC_IP}:8000/v1 \ | |
--adminurl http://${PUBLIC_IP}:8000/v1 \ | |
--region ${REGION}" | |
fi | |
echo | |
echo "HEAT Setup Completed..." | |
echo | |
echo "You may need to restart the server for all changes to take effect..." | |
echo | |
echo "Start Heat API and ENGINE using following commands..." | |
echo "sudo service heat-api start" | |
echo "sudo service heat-engine start" | |
echo "heat logs are available in: /var/log/heat" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment