Skip to content

Instantly share code, notes, and snippets.

@tkishel
Last active October 3, 2019 21:39
Show Gist options
  • Save tkishel/85440c21cd4a28e8575f20a76da17936 to your computer and use it in GitHub Desktop.
Save tkishel/85440c21cd4a28e8575f20a76da17936 to your computer and use it in GitHub Desktop.
Reset a Replica for Reuse (aka RRR)
#!/bin/bash
# The Puppet Enterprise High Availability documentation states:
#
# Run the forget command whenever a replica node is destroyed,
# even if you plan to replace it with a replica with the same name.
#
# Some users prefer to forget and reuse (instead of destroy and replace) a replica.
# As an alternative, when `/opt/puppetlabs/bin/puppet-enterprise-uninstaller` isn't available,
# this script uninstalls Puppet Enterprise on the Replica.
echo "Verifying Replica ..."
server=`/opt/puppetlabs/puppet/bin/puppet config print server`
certname=`/opt/puppetlabs/puppet/bin/puppet config print certname`
if [ "${certname}X" == "${server}X" ]; then
echo "Error: this node is the Primary Master, not a Replica."
exit 1
fi
echo "Stopping Services on Replica ..."
/opt/puppetlabs/puppet/bin/puppet resource service mcollective ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service puppet ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pxp-agent ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-activemq ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-ace-server ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-console-services ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-orchestration-services ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-nginx ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-postgresql ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-puppetdb ensure=stopped
/opt/puppetlabs/puppet/bin/puppet resource service pe-puppetserver ensure=stopped
echo "Uninstalling Packages and Files on Replica ..."
if [ -f /etc/debian_version ]; then
dpkg --list | egrep 'mcollective|puppet|pe-[a-z]' | cut -d ' ' -f 3 | xargs apt-get remove --purge -y
rm -f /etc/apt/sources.list.d/puppetlabs-pc1.list* /etc/apt/sources.list.d/puppet_enterprise.list*
rm -f /etc/default/pe-*
apt-get update
rm -rf /etc/puppetlabs/* /opt/puppetlabs/* /var/log/puppetlabs/*
elif [ -f /etc/redhat-release ]; then
rpm -qa | egrep 'mcollective|puppet|pe-[a-z]' | xargs yum remove -y
rm -f /etc/yum.repos.d/pc_repo.repo /etc/yum.repos.d/pe_repo.repo /etc/yum.repos.d/puppet_enterprise.repo
rm -f /etc/sysconfig/pe-*
rm -rf /etc/puppetlabs/* /opt/puppetlabs/* /var/log/puppetlabs/*
else
echo "Error: unable to determine operating system of this Replica."
exit 1
fi
echo "Done."
echo
echo "Please perform the following manual steps ..."
echo
echo "#### On the Primary Master, forget and purge the Replica:"
echo
echo "puppet infrastructure forget ${certname}"
echo "puppet node purge ${certname}"
echo
echo "#### On the Replica, reinstall the Puppet Agent and run Puppet:"
echo
echo "curl -k https://${server}:8140/packages/current/install.bash | sudo bash"
echo "puppet agent -t"
echo
echo "#### On the Primary Master, sign the certificate for the Replica:"
echo
echo "puppet cert sign ${certname}"
echo "puppetserver ca sign -cert ${certname} # in PE 2019 or newer"
echo
echo "#### On the Replica, run Puppet:"
echo
echo "puppet agent -t"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment