diff --git a/rabbit-rescue/README.md b/rabbit-rescue/README.md new file mode 100644 index 00000000..89ad613a --- /dev/null +++ b/rabbit-rescue/README.md @@ -0,0 +1,30 @@ +# Rabbit-Rescue + +Use this script to rebuild the vhosts and permissions in Rabbitmq in case it gets borked.
*(Don't even ask how I managed to do this...)* + +This script is loosely based on informatoin gleaned from [this RedHat article](https://access.redhat.com/articles/1167113), and was added to this repo based on [this conversation](http://eavesdrop.openstack.org/irclogs/%23openstack-ansible/%23openstack-ansible.2020-03-11.log.html).
Apparently I'm not the only one who has inadvertently destroyed their RabbitMQ installation, so this may be helpful to others in the future. + +Note: For clustered installations, this needs to run only on a single node. + +## Usage: + +- Clone this repo into /opt on your deployment host. + +- Edit the Bash array `all_services` and populate with the services you were using in RabbitMQ. + +- Populate the service secrets with the information found in your `/etc/openstack_deploy/user_secrets.yml` file. + - _(this is quite possibly something we could try to do automatically in a future update)_ + +- Execute this from the deployment host, targeting one of your RabbitMQ containers: + - ``` + # cd /opt/openstack-ansible + # ansible rabbit_mq_container -m copy -a 'src=/opt/openstack-ops/rabbit-rescue/rabbit-rescue.sh dest=/tmp/rabbit-rescue.sh mode=preserve' + # ansible rabbit_mq_container -m shell -a '/tmp/rabbit-rescue.sh' + ``` + - Profit! + +## Alternative Usage: + +- Copy the script file down to one of your RabbitMQ Containers. + +- Edit the contents per the above instructions, and execute it. \ No newline at end of file diff --git a/rabbit-rescue/rabbit-rescue.sh b/rabbit-rescue/rabbit-rescue.sh new file mode 100755 index 00000000..8897dedc --- /dev/null +++ b/rabbit-rescue/rabbit-rescue.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# +# Copyright 2020 Henry Bonath +# +# 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. +# +# **Use this script at your own risk - we do our best to not do any damage but YMMV!** + + +# All Services - populate this array with the names of the services you are running in your cluster +# some defaults are provided below +all_services=( cinder nova neutron heat glance ceilometer ) + +# Rabbit Secrets - populate the vars below with information found in /etc/openstack_deploy/user_secrets.yml +# These will be used when re-creating the vhosts and *must* be named based on the service names above +cinder_oslomsg_rpc_password=MYSECRETcinderPassw0rd +nova_oslomsg_rpc_password=MYSECRETnovaPassw0rd +neutron_oslomsg_rpc_password=MYSECRETneutronPassw0rd +heat_oslomsg_rpc_password=MYSECRETheatPassw0rd +glance_oslomsg_rpc_password=MYSECRETglancePassw0rd +ceilometer_oslomsg_rpc_password=MYSECRETceilopmeterPassw0rd + + +for service in "${all_services[@]}"; do + + if ($(rabbitmqctl list_vhosts | grep "/$service" > /dev/null)); then + echo "/$service vhost already exists, skipping." + else + echo "Creating /$service vhost:" + rabbitmqctl add_vhost /$service + fi + + if ($(rabbitmqctl list_users | grep "$service" > /dev/null)); then + echo "$service user already exists, skipping." + else + echo "Creating $service user:" + secret=$(printf \$"$service"_oslomsg_rpc_password) + eval $(echo rabbitmqctl add_user $service $secret) + fi + + if ($(rabbitmqctl list_permissions --vhost /$service | grep 'does not exist' > /dev/null)); then + echo "Setting $service permissions:" + rabbitmqctl set_permissions $service -p /$service ".*" ".*" ".*" + else + echo "$service permissions already set, skipping." + fi + +done + + +exit 0