Created
September 4, 2018 12:27
-
-
Save kclinden/8b5b2f29332b9e5201371aaeddf88880 to your computer and use it in GitHub Desktop.
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 | |
| #Name: Install Satellite Tools | |
| #Creator: Kasey Linden / Lesley Kimmel | |
| #Version: v0.8.0 | |
| #Description: Used as a software component through vRealize Automation to install required agents for Red Hat Satellite. Inputs must be configured for SAT_ACTIVATION_KEY, SAT_ORGANIZATION, and SAT_SERVER through property bindings or with values directly configured in the software component. | |
| ###CONFIGURATION#### | |
| #SATELLITE VARIBLES# | |
| #VARIABLES ARE ONLY USED FOR SCRIPT EXECUTION OUTSIDE OF VRA. VRA PROVIDES VARIABLES VIA SOFTWARE COMPONENT. | |
| #CHECK FOR ENVIRONMENT VARIABLES SET BY VRA SOFTWARE COMPONENT ELSE USE DEFAULTS | |
| activation_key=${SAT_ACTIVATION_KEY:-""} | |
| satellite_organization=${SAT_ORGANIZATION:-""} | |
| satellite_server=${SAT_SERVER:-""} | |
| consumer_key="http://${satellite_server}/pub/katello-ca-consumer-latest.noarch.rpm" | |
| puppet_conf='/etc/puppetlabs/puppet/puppet.conf' | |
| #################### | |
| rollback_subscribe() { | |
| echo ${msg+"Unregistering from Satellite server"} | |
| subscription-manager unregister | |
| check_rc $? 0 "${msg}" 1 | |
| echo ${msg+"Removing local subscription information"} | |
| subscription-manager clean | |
| check_rc $? 0 "${msg}" 1 | |
| } | |
| rollback_attach() { | |
| echo ${msg+"Removing all current subscriptions"} | |
| subscription-manager remove --all | |
| check_rc $? 0 "${msg}" 1 | |
| } | |
| cleanup() { | |
| msg="" | |
| case ${1} in | |
| 2) | |
| rollback_subscribe | |
| ;; | |
| 3) | |
| rollback_attach | |
| ;; | |
| esac | |
| cursor=$(( ${1} - 1 )) | |
| [ ${cursor} -gt 0 ] && cleanup ${cursor} | |
| } | |
| check_rc() { | |
| if [ ${1} -ne ${2} ] | |
| then | |
| echo "Failed during step: ${3}" | |
| cleanup ${4} | |
| exit ${4} | |
| fi | |
| unset msg | |
| } | |
| # Clean up stale yum data | |
| echo ${msg:="Cleaning YUM Cache"} | |
| rm -rf /var/cache/yum/* | |
| check_rc $? 0 "${msg}" 1 | |
| #Install Katello CA Package | |
| echo ${msg:="Installing consumer key"} | |
| yum localinstall --nogpgcheck -y -q "${consumer_key}" | |
| check_rc $? 0 "${msg}" 1 | |
| #Regsiter Server to Satellite Server | |
| echo ${msg:="Registering to Satellite server"} | |
| subscription-manager register --org $satellite_organization --activationkey $activation_key | |
| check_rc $? 0 "${msg}" 2 | |
| echo ${msg:="Attaching Red Hat subscription(s)"} | |
| subscription-manager attach --auto | |
| # Ensure that satellite-tools repo is enabled | |
| subscription-manager list | grep "^Status:" | grep -i "unknown" | |
| check_rc $? 1 "${msg}" 3 | |
| echo ${msg:="Enabling Satellite Tools Repo(s)"} | |
| subscription-manager repos --list-enabled | grep -i satellite-tools | |
| check_rc $? 0 "${msg}" 3 | |
| yum update -y -q | |
| #Install Katello Agent | |
| rpm -qi 'katello-agent' | |
| rc=$? | |
| if [ $rc -ne 0 ] | |
| then | |
| echo ${msg:="Installing Katello Agent"} | |
| yum install katello-agent -y -q | |
| check_rc $? 0 "${msg}" 5 | |
| fi | |
| #Install Puppet Agent | |
| rpm -qi 'puppet' | |
| rc=$? | |
| if [ $rc -ne 0 ] ; then | |
| echo ${msg:="Installing Puppet Agent"} | |
| yum install puppet-agent -y -q | |
| check_rc $? 0 "${msg}" 6 | |
| fi | |
| #Update Puppet File Config with Puppet Config | |
| echo ${msg:="Configuring Puppet Agent"} | |
| # Temporary workaround to configure puppet.conf because | |
| # the Puppet 4 'puppet' utility does not create the 'main' section | |
| echo '[main]' >> $puppet_conf && | |
| echo 'digest_algorithm = sha256' >> $puppet_conf && | |
| puppet config set ca_server $satellite_server --section agent && \ | |
| puppet config set server $satellite_server --section agent && \ | |
| puppet config set certname $(hostname -f) --section agent #&& \ | |
| #puppet config set digest_algorithm sha256 --section main #&& \ | |
| #puppet config set environment $puppet_environment --section agent | |
| check_rc $? 0 "${msg}" 7 | |
| #Enable and Start Services | |
| #echo ${msg:="Enabling and starting services"} | |
| echo ${msg:="Enabling services"} | |
| systemctl enable goferd #&& \ | |
| # Do not enable Puppet here to account for certmonger issue | |
| # attaching to DBus because system needs to be restarted. | |
| # We will enable the service just before our final restart. | |
| #systemctl enable puppet | |
| # Don't start puppet and gofer services. We will accomplish | |
| # this via a system restart later. | |
| check_rc $? 0 "${msg}" 8 | |
| # Force initial Puppet checkin in order to make system known to Puppet master | |
| # This is a bit of a workaround as most Puppet first-runs seem to fail | |
| # We will check in here and immediately reboot to get a good run (hopefully). | |
| echo ${msg:="Priming Puppet (workaround)"} | |
| # Make the PATH variable available to subprocesses | |
| export PATH | |
| # Execute the Puppet agent in the foreground | |
| /bin/puppet agent --onetime --no-daemonize --waitforcert=120 --no-usecacheonfailure --ignorecache --noop --verbose | |
| # Run a 2nd time to retrieve and upload custom facts | |
| /bin/puppet agent --onetime --no-daemonize --waitforcert=120 --no-usecacheonfailure --ignorecache --noop --verbose | |
| echo "Puppet agent run returned: $?" | |
| # Exit with success because the above call to Puppet Agent is | |
| # expected to fail. | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment