Sample Header Ad - 728x90

SH script fails when something already exists

1 vote
0 answers
69 views
I have a problem with my SH script, I'm writing a SH script that automates the installation of OpenStack Keystone, and also uses a small configuration file, everything works fine but due to a syntax error on my part OpenStack command, script fails when something has already been created, example RabbitMQ user, Project or OpenStack User The contents of my SH script is this:
#!/usr/bin/env bash

set -e
set -o xtrace

source "$PWD/install-keystone.conf"

conf=/etc/keystone/keystone.conf

if [ "$EUID" -ne 0 ]; then 
  echo "To proceed with the installation of OpenStack Keystone you must be root user"
  echo "Please run as root"
  exit 1
fi


config_mysql()
{
apt install mariadb-server python3-pymysql -y


if ! test -f /etc/mysql/mariadb.conf.d/99-openstack.cnf; then
cat >> /etc/mysql/mariadb.conf.d/99-openstack.cnf > /root/admin-openrc.sh > /root/demo-openrc.sh << EOF
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=demo
export OS_USERNAME=demo
export OS_PASSWORD=$DEMO_PASSWORD
export OS_AUTH_URL=http://$HOST_IP:5000/v3 
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
EOF
fi

}

config_mysql
config_rabbitmq
install_pkgs
create_keystone_database
conf_keystone
create_projects_users
request_auth_token
create_cli_environment_scripts

echo ""
echo ""
echo ""
echo "This is your host IP address: $HOST_IP"
echo "Keystone URL is available at http://$HOST_IP:5000/ "
echo "The default users are: admin and demo"
echo "The password of administrator is '$ADMIN_PASSWORD'"
echo ""
echo "OpenStack Keystone has been successfully installed!"
echo "Learn more about Keystone in guides and more from : https://docs.openstack.org/keystone/latest/ "
echo ""
echo "Now connect this Keystone installation to other OpenStack services"
echo "It is recommended to subsequently install Glance (Image Service) on your controller node"
exit
My custom config file:
HOST_IP=
ADMIN_PASSWORD=
DEMO_PASSWORD=
DATABASE_PASSWORD=
RABBITMQ_PASSWORD=
I realized that it initially failed because I made a mistake in the
--os-username
section I didn't enter the username and the script failed because of me now as soon as it comes to OpenStack user creation on RabbitMQ it says the user already exists but the script fails without ignoring that message Is there a way to ignore the message? And I use
-e
, to avoid having the script continue due to an error, but even if something exists it still marks it as an error and the script doesn't proceed
Asked by Steforgame 910 (11 rep)
Oct 31, 2023, 08:52 AM
Last activity: Oct 31, 2023, 09:03 AM