Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
0fa5d146 Dominic Cleal
<%#
kind: snippet
name: redhat_register
f9889300 Ondrej Prazak
model: ProvisioningTemplate
snippet: true
9f802d90 Marek Hulan
description: |
Red Hat Registration Snippet

General parameters:

redhat_install_host_tools = [true|false] Install the katello-host-tools yum/dnf plugins.

redhat_install_host_tracer_tools = [true|false] Install the katello-host-tools Tracer yum/dnf plugin.

activation_key = <key> Activation key string, not needed if using
subscription-manager with username/password

Parameters for use with subscription-manager (Red Hat CDN, Satellite, or Katello)

subscription_manager = 'true' You're going to use subscription-manager

subscription_manager_auto_attach = 'false' Run attach --auto after registering.

subscription_manager_username = <username> Username for subscription-manager

subscription_manager_password = <password> Password for subscription-manager

subscription_manager_certpkg_url = <url> Custom certificate package URL

subscription_manager_org = <org name> Organization name, if required

subscription_manager_repos = <repos> Additional repositories to enable
after registration.
Seperate multiple repositories with commas.

subscription_manager_override_repos_cost = <cost> Override repository cost

subscription_manager_pool = <pool> Specific subscription pool to use

only_subscription_manager_repos = 'true' dnf/yum should only use repos managed by sub-man

http-proxy = <host> Proxy hostname to be used for registration

http-proxy-port = <port> Proxy port to be used for registration

http-proxy-user = <user> Proxy user to be used for registration

http-proxy-password = <password> Proxy password to be used for registration

syspurpose_role Sets the system purpose role

syspurpose_usage Sets the system purpose usage

syspurpose_sla Sets the system purpose SLA

syspurpose_addons Sets the system purpose add-ons. Separate multiple
values with commas.

Set these parameters if you're using rhnreg_ks:

spacewalk_host = <hostname> Hostname of Spacewalk server
d96043f5 Tomer Brisker
-%>
3bd6f09c Stephen Benjamin
<%
# Katello or subscription-manager:
if host_param_true?('subscription_manager') || host_param('kt_activation_keys')
registration_type = 'subscription_manager'
# Spacewalk:
elsif host_param('spacewalk_host')
registration_type = 'spacewalk'
bf03a259 Pat Riehecky
else
registration_type = nil
end
-%>
# registration_type = '<%= registration_type %>'
<% if registration_type == 'subscription_manager' -%>
3bd6f09c Stephen Benjamin
<%
if host_param('kt_activation_keys')
subscription_manager_certpkg_url = subscription_manager_configuration_url(@host)
subscription_manager_org = @host.rhsm_organization_label
activation_key = host_param('kt_activation_keys')
7599ffd2 Jeffrey Cutter
redhat_install_host_tools = host_param_true?('redhat_install_host_tools', true)
redhat_install_host_tracer_tools = host_param_true?('redhat_install_host_tracer_tools')
3bd6f09c Stephen Benjamin
else
subscription_manager_certpkg_url = host_param('subscription_manager_certpkg_url')
subscription_manager_org = host_param('subscription_manager_org')
activation_key = host_param('activation_key')
91de0279 Marek Hulan
redhat_install_host_tools = host_param_true?('redhat_install_host_tools')
redhat_install_host_tracer_tools = host_param_true?('redhat_install_host_tracer_tools')
3bd6f09c Stephen Benjamin
end
bf03a259 Pat Riehecky
-%>
3bd6f09c Stephen Benjamin
f7e8785b Tomer Brisker
echo "##############################################################"
echo "################# SUBSCRIPTION MANAGER #######################"
echo "##############################################################"
3bd6f09c Stephen Benjamin
echo
echo "Starting the subscription-manager registration process"

dd26cc3f nofaralfasi
# Set up subscription-manager
<%= snippet("subscription_manager_setup", variables: { subman_setup_scenario: 'provisioning' }).strip -%>
4e205ba1 Ewoud Kohl van Wijngaarden
bf03a259 Pat Riehecky
<%- if (host_param('syspurpose_role') || host_param('syspurpose_usage') || host_param('syspurpose_sla') || host_param('syspurpose_addons')) -%>
8a7136dd pandrieux
# Avoid timeout accessing unreachable repo on air gapped infrastructure,
4e205ba1 Ewoud Kohl van Wijngaarden
# assuming subscription-manager-syspurpose is installed in custom packages section.
if ! rpm --query --quiet subscription-manager-syspurpose ; then
dd26cc3f nofaralfasi
$PKG_MANAGER_INSTALL subscription-manager-syspurpose
3bd6f09c Stephen Benjamin
fi
75a1dcd8 Tomas Strachota
if [ -f /usr/sbin/syspurpose ]; then
bf03a259 Pat Riehecky
<%- if host_param('syspurpose_role') -%>
75a1dcd8 Tomas Strachota
syspurpose set-role "<%= host_param('syspurpose_role') %>"
bf03a259 Pat Riehecky
<%- end -%>
<%- if host_param('syspurpose_usage') -%>
75a1dcd8 Tomas Strachota
syspurpose set-usage "<%= host_param('syspurpose_usage') %>"
bf03a259 Pat Riehecky
<%- end -%>
<%- if host_param('syspurpose_sla') -%>
75a1dcd8 Tomas Strachota
syspurpose set-sla "<%= host_param('syspurpose_sla') %>"
bf03a259 Pat Riehecky
<%- end -%>
<%- if host_param('syspurpose_addons') -%>
75a1dcd8 Tomas Strachota
<%- addons = host_param('syspurpose_addons').split(',')
.map { |add_on| "'#{add_on.strip}'" }.join(" ") %>
syspurpose add-addons <%= addons %>
bf03a259 Pat Riehecky
<%- end -%>
75a1dcd8 Tomas Strachota
else
echo "Syspurpose CLI not found."
fi
bf03a259 Pat Riehecky
<% end -%>
75a1dcd8 Tomas Strachota
bf03a259 Pat Riehecky
<% if host_param('http-proxy') -%>
3bd6f09c Stephen Benjamin
subscription-manager config --server.proxy_hostname='<%= host_param("http-proxy") %>'
bf03a259 Pat Riehecky
<% if host_param('http-proxy-user') -%>
3bd6f09c Stephen Benjamin
subscription-manager config --server.proxy_user='<%= host_param("http-proxy-user") %>'
bf03a259 Pat Riehecky
<% end -%>
<% if host_param('http-proxy-password') -%>
3bd6f09c Stephen Benjamin
subscription-manager config --server.proxy_password='<%= host_param("http-proxy-password") %>'
bf03a259 Pat Riehecky
<% end -%>
<% if host_param('http-proxy-port') -%>
3bd6f09c Stephen Benjamin
subscription-manager config --server.proxy_port='<%= host_param("http-proxy-port") %>'
bf03a259 Pat Riehecky
<% end -%>
<% end -%>
dd26cc3f nofaralfasi
bf03a259 Pat Riehecky
<% if host_param('subscription_manager_username') && host_param('subscription_manager_password') -%>
<% if host_param('subscription_manager_pool') -%>
3bd6f09c Stephen Benjamin
subscription-manager register --name="<%= @host.name %>" --username='<%= host_param("subscription_manager_username") %>' --password='<%= host_param("subscription_manager_password") %>'
subscription-manager attach --pool='<%= host_param('subscription_manager_pool') %>'
bf03a259 Pat Riehecky
<% else -%>
91de0279 Marek Hulan
subscription-manager register --name="<%= @host.name %>" --username='<%= host_param("subscription_manager_username") %>' --password='<%= host_param("subscription_manager_password") %>' --auto-attach
bf03a259 Pat Riehecky
<% end -%>
3bd6f09c Stephen Benjamin
bf03a259 Pat Riehecky
<% elsif activation_key -%>
3bd6f09c Stephen Benjamin
subscription-manager register --name="<%= @host.name %>" --org='<%= subscription_manager_org %>' --activationkey='<%= activation_key %>'
bf03a259 Pat Riehecky
<% else -%>
3bd6f09c Stephen Benjamin
echo "No activation key found: Not registering to subscription manager"
bf03a259 Pat Riehecky
<% end -%>
3bd6f09c Stephen Benjamin
bf03a259 Pat Riehecky
<% if host_param_true?('only_subscription_manager_repos') -%>
3e693b07 Bernhard Suttner
for subman_config_file in /etc/yum/pluginconf.d/subscription-manager.conf /etc/dnf/plugins/subscription-manager.conf; do
if [ -f $subman_config_file ]; then
egrep -q "^disable_system_repos=" $subman_config_file
if [ "$?" -eq 0 ]; then
sed s/^disable_system_repos=.*/disable_system_repos=1/ $subman_config_file >"${subman_config_file}.new"
mv -f "${subman_config_file}.new" $subman_config_file
else
echo "disable_system_repos=1" >>$subman_config_file
fi
fi
done
bf03a259 Pat Riehecky
<% end -%>
3e693b07 Bernhard Suttner
f40ef0db dforste
<% if host_param_true?('subscription_manager_auto_attach', false) -%>
subscription-manager attach --auto

<% end -%>
bf03a259 Pat Riehecky
<% if host_param('subscription_manager_repos') -%>
3bd6f09c Stephen Benjamin
# workaround for RHEL 6.4 bug https://bugzilla.redhat.com/show_bug.cgi?id=1008016
subscription-manager repos --list > /dev/null
e392b9f9 Tomer Brisker
<%= "subscription-manager repos --enable #{host_param('subscription_manager_repos').gsub(/,\s*/, ' --enable ')}" %>
bf03a259 Pat Riehecky
<% end -%>
3bd6f09c Stephen Benjamin
bf03a259 Pat Riehecky
<% if host_param('subscription_manager_override_repos_cost') -%>
d96043f5 Tomer Brisker
for repo in $(subscription-manager repos --list-enabled | grep "Repo ID:" | awk -F' ' '{ print $3 }'); do
<%= "subscription-manager repo-override --list --repo $repo | grep 'cost:' &>/dev/null || subscription-manager repo-override --repo $repo --add=cost:#{host_param('subscription_manager_override_repos_cost')}" %>
done
bf03a259 Pat Riehecky
<% end -%>
d96043f5 Tomer Brisker
bf03a259 Pat Riehecky
<% if redhat_install_host_tools -%>
dd26cc3f nofaralfasi
$PKG_MANAGER_INSTALL katello-host-tools
bf03a259 Pat Riehecky
<% end -%>
91de0279 Marek Hulan
bf03a259 Pat Riehecky
<% if redhat_install_host_tracer_tools -%>
dd26cc3f nofaralfasi
$PKG_MANAGER_INSTALL katello-host-tools-tracer
bf03a259 Pat Riehecky
<% end -%>
<% end -%>
3bd6f09c Stephen Benjamin
bf03a259 Pat Riehecky
<% if registration_type == 'spacewalk' -%>
f7e8785b Tomer Brisker
echo "##############################################################"
echo "################ SPACEWALK REGISTRATION ######################"
echo "##############################################################"
13833d4d Dominic Cleal
bf03a259 Pat Riehecky
<% if host_param('activation_key') -%>
857a5d14 Daniel Lobato Garcia
rhn_activation_key="<%= host_param('activation_key') -%>"
satellite_hostname="<%= host_param('spacewalk_host') -%>"
e8e6a960 Dominic Cleal
rhn_cert_file="RHN-ORG-TRUSTED-SSL-CERT"
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
# Obtain our RHN Satellite Certificate
echo "Obtaining RHN SSL certificate"
1d5bddd3 Dominic Cleal
curl -o /usr/share/rhn/$rhn_cert_file -k https://$satellite_hostname/pub/$rhn_cert_file
3bd6f09c Stephen Benjamin
1d5bddd3 Dominic Cleal
<% if @host.operatingsystem.name == 'SLES' -%>
3bd6f09c Stephen Benjamin
# If SLES then add CA Cert to CA Certs for curl
cp /usr/share/rhn/$rhn_cert_file /etc/ssl/certs/
ln -s /etc/ssl/certs/$rhn_cert_file /etc/ssl/certs/`openssl x509 -hash -noout -in /etc/ssl/certs/$rhn_cert_file`.0
e8e6a960 Dominic Cleal
<% 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..."
3bd6f09c Stephen Benjamin
<% if @host.operatingsystem.name == 'SLES' && @host.operatingsystem.major.to_i < 12 -%>
service haldaemon restart
1d5bddd3 Dominic Cleal
<% else -%>
3bd6f09c Stephen Benjamin
service messagebus restart
service hald restart
1d5bddd3 Dominic Cleal
<% end -%>
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
3bd6f09c Stephen Benjamin
bf03a259 Pat Riehecky
<% else -%>
3bd6f09c Stephen Benjamin
echo "No activation key found: Not registering"
bf03a259 Pat Riehecky
<% end -%>
<% end -%>