Reinstall OpenStack on a running system Part 1: Cleanup

I have three home servers in my closet. Ok, server is just a glorified way to call three headless cheap desktop machines i assembled for my home needs and testing. From now on we'll call them cloud, cloud2 and cloud3 (i know pretty clever names!!)
One of the things that i've spent years testing is: OpenStack, after upgrading and checking out new features, i broke it so much that i thought that the best should be to uninstall everything and then install it again from scratch.
Unfortunately i can't do that, i have a lot of services in the three boxes: cloud (the controller) has a DNS, two ceph OSD's, my IRC permanent connection, it's my point of entry from the world to my home setup, docker images and some other stuff, so i can't wipe the system and start from scratch, the other two servers are ceph nodes and compute nodes for OpenStack, so technically i could install the controller services in one of them but i still have to clean cloud.
Since i still had to clean the current controller i decided to uninstall OpenStack and then reinstall it in the same server.

And yes, this is a the begining of a horror story…

Cleaning Up

First i googled possible ways of cleaning an OpenStack installation and i was happy to find enakai00 github repo that has some cool scripts tha deploy and configure RDO using Packstack, i was even happier when i found a cleanup.sh script that has been continuosly updated since grizzly.
I there are some stuff in the script that i didn't needed to do: switching off iptables, deleting perl, scsi stuff and loopback devices and removing all my virtual machines. So i did some modifications to the script:

#!/bin/sh
 
function cleanup_all {
    services=$(systemctl list-unit-files | grep -E "(redis|mariadb|openstack|neutron|rabbitmq-server).*\s+enabled" | cut -d" " -f1)
    for s in $services; do
        systemctl stop $s
        systemctl disable $s;
    done
 
    # Just remove running VM's
    for x in $(virsh list | grep instance- | awk '{print $2}'); do
        virsh destroy $x
        virsh undefine $x
    done
 
    yum remove -y "rabbitmq-server*" \
        "redis*" "*openstack*" "*neutron*" "*nova*" "*keystone*" \
        "*glance*" "*cinder*" "*heat*" "*ceilometer*" openvswitch \
        "*mariadb*" "*mongo*" "*memcache*" \
        "rdo-release-*"
 
    for x in nova glance cinder keystone horizon neutron heat ceilometer;do
        rm -rf /var/lib/$x /var/log/$x /etc/$x
    done
 
    rm -rf /root/.my.cnf /var/lib/mysql \
        /etc/openvswitch /var/log/openvswitch 
 
    if vgs cinder-volumes; then
        vgremove -f cinder-volumes
    fi
 
    for x in $(losetup -a | grep -v docker | sed -e 's/:.*//g'); do
        losetup -d $x
    done
}
 
# main
 
echo "This will completely uninstall all openstack-related components."
echo -n "Are you really sure? (yes/no) "
read answer
if [[ $answer == "yes" ]]; then
    # Show everything
    cleanup_all 
    echo "Finished. Reboot the server to refresh processes."
else
    echo "Cancelled."
fi

I'm preparing Next of the Series: Reinstall OpenStack on a running system Part 2: Dockerizing OpenStack

References