foreman/app/views/unattended/snippets/_redhat_register.erb @ 013ee65a
0fa5d146 | Dominic Cleal | <%#
|
|
kind: snippet
|
|||
name: redhat_register
|
|||
%>
|
|||
8e9b8d69 | Ohad Levy | # Red Hat Registration Snippet
|
|
13833d4d | Dominic Cleal | #
|
|
e8e6a960 | Dominic Cleal | # Set these parameters if you're using rhnreg_ks:
|
|
#
|
|||
6d755dd0 | Dominic Cleal | # spacewalk_type = 'site' (local Spacewalk/Satellite server)
|
|
# = 'hosted' (RHN hosted)
|
|||
13833d4d | Dominic Cleal | # spacewalk_host = <hostname> (hostname of Spacewalk server, optional for
|
|
# RHN hosted)
|
|||
#
|
|||
e8e6a960 | Dominic Cleal | # Set these parameters if you're using subscription-manager:
|
|
#
|
|||
# subscription_manager = 'true' (you're going to use subscription-manager)
|
|||
#
|
|||
# subscription_manager_username = <username> (if using hosted RHN)
|
|||
#
|
|||
# subscription_manager_password = <password> (if using hosted RHN)
|
|||
#
|
|||
# subscription_manager_host = <hostname> (hostname of SAM/Katello
|
|||
# installation, if using SAM)
|
|||
#
|
|||
# subscription_manager_org = <org name> (organization name, if using
|
|||
# SAM/Katello)
|
|||
#
|
|||
# subscription_manager_repos = <repos> (comma separated list of repos (like
|
|||
# rhel-6-server-optional-rpms) to
|
|||
# enable after registration)
|
|||
#
|
|||
013ee65a | Dominic Cleal | # subscription_manager_pool = <pool> (specific pool to be used for
|
|
# registration)
|
|||
#
|
|||
e8e6a960 | Dominic Cleal | # Set this parameter regardless of which registration method you're using:
|
|
#
|
|||
# activation_key = <key> (activation key string, not needed if using
|
|||
# subscription-manager with hosted RHN)
|
|||
#
|
|||
<% unless @host.params['subscription_manager'] %>
|
|||
<% type = @host.params['spacewalk_type'] || 'hosted' %>
|
|||
13833d4d | Dominic Cleal | ||
e8e6a960 | Dominic Cleal | <% if @host.params['activation_key'] %>
|
|
# Discovered Activation Key <%= @host.params['activation_key'] %>
|
|||
rhn_activation_key="<%= @host.params['activation_key'] -%>"
|
|||
13833d4d | Dominic Cleal | ||
e8e6a960 | Dominic Cleal | <% if type == "site" -%>
|
|
satellite_hostname="<%= @host.params['spacewalk_host'] -%>"
|
|||
rhn_cert_file="RHN-ORG-TRUSTED-SSL-CERT"
|
|||
<% else -%>
|
|||
satellite_hostname="<%= @host.params['spacewalk_host'] || 'xmlrpc.rhn.redhat.com' -%>"
|
|||
rhn_cert_file="RHNS-CA-CERT"
|
|||
<% end -%>
|
|||
8e9b8d69 | Ohad Levy | ||
e8e6a960 | Dominic Cleal | echo "Registering to RHN Satellite at [$satellite_hostname]"
|
|
echo "Using Registration Key [$rhn_activation_key]"
|
|||
8e9b8d69 | Ohad Levy | ||
e8e6a960 | Dominic Cleal | <% if type == 'site' -%>
|
|
# Obtain our RHN Satellite Certificate
|
|||
echo "Obtaining RHN SSL certificate"
|
|||
wget http://$satellite_hostname/pub/$rhn_cert_file -O /usr/share/rhn/$rhn_cert_file
|
|||
<% end -%>
|
|||
8e9b8d69 | Ohad Levy | ||
e8e6a960 | Dominic Cleal | # Update our up2date configuration file
|
|
echo "Updating SSL CA Certificate to /usr/share/rhn/$rhn_cert_file"
|
|||
sed -i -e "s|^sslCACert=.*$|sslCACert=/usr/share/rhn/$rhn_cert_file|" /etc/sysconfig/rhn/up2date
|
|||
8e9b8d69 | Ohad Levy | ||
e8e6a960 | Dominic Cleal | # Update our Satellite Hostname
|
|
echo "Updating Satellite Hostname to [$satellite_hostname]"
|
|||
sed -i -e "s|^serverURL=.*$|serverURL=https://$satellite_hostname/XMLRPC|" /etc/sysconfig/rhn/up2date
|
|||
sed -i -e "s|^noSSLServerURL=.*$|noSSLServerURL=https://$satellite_hostname/XMLRPC|" /etc/sysconfig/rhn/up2date
|
|||
8e9b8d69 | Ohad Levy | ||
e8e6a960 | Dominic Cleal | # Restart messagebus/HAL to try and prevent hardware detection errors in rhnreg_ks
|
|
echo "Restarting services..."
|
|||
service messagebus restart
|
|||
service hald restart
|
|||
8e9b8d69 | Ohad Levy | ||
e8e6a960 | Dominic Cleal | # Now, perform our registration
|
|
# (might get hardware errors here, due to dbus/messagebus lameness. These are safe to ignore.)
|
|||
echo -n "Performing RHN Registration... "
|
|||
rhnreg_ks --activationkey=$rhn_activation_key
|
|||
echo "done."
|
|||
8e9b8d69 | Ohad Levy | ||
e8e6a960 | Dominic Cleal | # Check we registered
|
|
echo -n "Checking System Registration... "
|
|||
if ! rhn_check; then
|
|||
echo "FAILED"
|
|||
echo " >> RHN Registration FAILED. Please Investigate. <<"
|
|||
else
|
|||
echo "registration successful."
|
|||
fi
|
|||
<% else %>
|
|||
# Not registering - host.params['activation_key'] not found.
|
|||
<% end %>
|
|||
<% else %>
|
|||
echo "Starting the subscription-manager registration process"
|
|||
yum -t -y -e 0 install subscription-manager yum-utils
|
|||
<% (enabled_repos = "yum-config-manager --enable #{@host.params['subscription_manager_repos'].gsub(',', ' ')}") if @host.params['subscription_manager_repos'] %>
|
|||
<% if @host.params['subscription_manager_username'] && @host.params['subscription_manager_password'] %>
|
|||
subscription-manager register --username="<%= @host.params['subscription_manager_username'] %>" --password="<%= @host.params['subscription_manager_password'] %>" --auto-attach
|
|||
013ee65a | Dominic Cleal | <% if @host.params['subscription_manager_pool'] %>
|
|
subscription-manager attach --pool="<%= @host.params['subscription_manager_pool'] %>"
|
|||
<% end %>
|
|||
e8e6a960 | Dominic Cleal | # workaround for RHEL 6.4 bug https://bugzilla.redhat.com/show_bug.cgi?id=1008016
|
|
subscription-manager repos --list > /dev/null
|
|||
<%= enabled_repos if enabled_repos %>
|
|||
<% elsif @host.params['activation_key'] %>
|
|||
rpm -Uvh <%= @host.params['subscription_manager_host'] %>/pub/candlepin-cert-consumer-latest.noarch.rpm
|
|||
subscription-manager register --org="<%= @host.params['subscription_manager_org'] %>" --activationkey="<%= @host.params['activation_key'] %>"
|
|||
# workaround for RHEL 6.4 bug https://bugzilla.redhat.com/show_bug.cgi?id=1008016
|
|||
subscription-manager repos --list > /dev/null
|
|||
<%= enabled_repos if enabled_repos %>
|
|||
<% else %>
|
|||
# Not registering host.params['activation_key'] not found.
|
|||
<% end %>
|
|||
<% end %>
|
|||
8e9b8d69 | Ohad Levy | # End Red Hat Registration Snippet
|