Skip to content

Commit

Permalink
Fixes #36525 - kickstart's RHSM line only works on RHEL hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpunk authored and stejskalleos committed Apr 17, 2024
1 parent 7d5fb02 commit bf03a25
Show file tree
Hide file tree
Showing 18 changed files with 1,196 additions and 84 deletions.
1 change: 1 addition & 0 deletions app/services/foreman/template_snapshot_service.rb
Expand Up @@ -71,6 +71,7 @@ def define_host_params(host)
"force-puppet" => "true",
"remote_execution_create_user" => "true",
"blacklist_kernel_modules" => "amodule",
"subscription_manager" => "true",
"subscription_manager_org" => "Org",
"activation_key" => "key",
"host_registration_insights" => "true",
Expand Down
Expand Up @@ -46,26 +46,28 @@ runcmd:
<%= indent(2) { snippet 'yum_proxy' } -%>
- |
<%= indent(2) { snippet 'ntp' } -%>
<% if rhel_compatible -%>
<% if host_param_true?('enable-epel') -%>
- |
<% if rhel_compatible && host_param_true?('enable-epel') -%>
<%= indent(2) { snippet 'epel' } -%>
<% end -%>
- |
<%= indent(2) { snippet 'redhat_register' } -%>
- |
<% end -%>
<% if host_enc['parameters']['realm'] && @host.realm && (@host.realm.realm_type == 'FreeIPA' || @host.realm.realm_type == 'Red Hat Identity Management') -%>
- |
<%= indent(2) { snippet 'freeipa_register' } %>
<% end -%>
- |
<%= indent(2) { snippet 'remote_execution_ssh_keys' } %>
- |
<%= indent(2) { snippet 'blacklist_kernel_modules' } %>
<% if chef_enabled -%>
- |
<% if chef_enabled %>
<%= indent(2) { snippet 'chef_client' } %>
<% end -%>
<% if puppet_enabled -%>
- |
<% if puppet_enabled %>
<% if host_param_true?('enable-puppetlabs-repo') || host_param_true?('enable-official-puppet8-repo') || host_param_true?('enable-official-puppet7-repo') || host_param_true?('enable-puppetlabs-puppet6-repo') || host_param_true?('enable-puppetlabs-puppet5-repo') -%>
<%= indent(2) { snippet 'puppetlabs_repo' } %>
<% end -%>
Expand Down
Expand Up @@ -71,6 +71,7 @@ description: |
use_ntp = host_param_true?('use-ntp', (is_fedora && os_major < 16) || (rhel_compatible && os_major <= 6))
iface = @host.provision_interface
appstream_present = false
use_rhsm = (@host.operatingsystem.name == 'RedHat' || @host.operatingsystem.name == 'RHEL') && os_major >= 8
-%>
# This kickstart file was rendered from the Foreman provisioning template "<%= @template_name %>".
# for <%= @host %> running <%= @host.operatingsystem.name %> <%= os_major %> <%= @arch %>
Expand Down Expand Up @@ -235,7 +236,7 @@ key --skip
<% else -%>
<%= @host.diskLayout %>
<% end -%>
<%= snippet('kickstart_rhsm') if rhel_compatible && os_major >= 9 -%>
<%= snippet('kickstart_rhsm') if use_rhsm -%>
<% if host_param_true?('use_graphical_installer') -%>
graphical
Expand Down Expand Up @@ -309,7 +310,7 @@ logger "Starting anaconda <%= @host %> postinstall"
<%= snippet 'epel' -%>
<% end -%>
<%= snippet 'redhat_register' if rhel_compatible && os_major < 9 -%>
<%= snippet 'redhat_register' if rhel_compatible && !use_rhsm -%>
<% if host_enc['parameters']['realm'] && @host.realm && (@host.realm.realm_type == 'FreeIPA' || @host.realm.realm_type == 'Red Hat Identity Management') -%>
<%= snippet 'freeipa_register' %>
Expand Down
Expand Up @@ -8,7 +8,6 @@ description: |
in the PKG_MANAGER env variable so it can be used in templates like this:
$PKG_MANAGER install -y pkg1 pkg2
-%>

if [ -f /etc/os-release ] ; then
. /etc/os-release
fi
Expand Down
Expand Up @@ -60,18 +60,19 @@ description: |
spacewalk_host = <hostname> Hostname of Spacewalk server
-%>
<%
# 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'
end if
%>
<% if registration_type == 'subscription_manager' %>
else
registration_type = nil
end
-%>
# registration_type = '<%= registration_type %>'
<% if registration_type == 'subscription_manager' -%>
<%
if host_param('kt_activation_keys')
subscription_manager_certpkg_url = subscription_manager_configuration_url(@host)
Expand All @@ -86,7 +87,7 @@ description: |
redhat_install_host_tools = host_param_true?('redhat_install_host_tools')
redhat_install_host_tracer_tools = host_param_true?('redhat_install_host_tracer_tools')
end
%>
-%>

echo "##############################################################"
echo "################# SUBSCRIPTION MANAGER #######################"
Expand All @@ -97,61 +98,61 @@ description: |
# Set up subscription-manager
<%= snippet("subscription_manager_setup", variables: { subman_setup_scenario: 'provisioning' }).strip -%>
<%- if (host_param('syspurpose_role') || host_param('syspurpose_usage') || host_param('syspurpose_sla') || host_param('syspurpose_addons')) %>
<%- if (host_param('syspurpose_role') || host_param('syspurpose_usage') || host_param('syspurpose_sla') || host_param('syspurpose_addons')) -%>
# Avoid timeout accessing unreachable repo on air gapped infrastructure,
# assuming subscription-manager-syspurpose is installed in custom packages section.
if ! rpm --query --quiet subscription-manager-syspurpose ; then
$PKG_MANAGER_INSTALL subscription-manager-syspurpose
fi

if [ -f /usr/sbin/syspurpose ]; then
<%- if host_param('syspurpose_role') %>
<%- if host_param('syspurpose_role') -%>
syspurpose set-role "<%= host_param('syspurpose_role') %>"
<%- end %>
<%- if host_param('syspurpose_usage') %>
<%- end -%>
<%- if host_param('syspurpose_usage') -%>
syspurpose set-usage "<%= host_param('syspurpose_usage') %>"
<%- end %>
<%- if host_param('syspurpose_sla') %>
<%- end -%>
<%- if host_param('syspurpose_sla') -%>
syspurpose set-sla "<%= host_param('syspurpose_sla') %>"
<%- end %>
<%- if host_param('syspurpose_addons') %>
<%- end -%>
<%- if host_param('syspurpose_addons') -%>
<%- addons = host_param('syspurpose_addons').split(',')
.map { |add_on| "'#{add_on.strip}'" }.join(" ") %>
syspurpose add-addons <%= addons %>
<%- end %>
<%- end -%>
else
echo "Syspurpose CLI not found."
fi
<% end %>
<% end -%>
<% if host_param('http-proxy') %>
<% if host_param('http-proxy') -%>
subscription-manager config --server.proxy_hostname='<%= host_param("http-proxy") %>'
<% if host_param('http-proxy-user') %>
<% if host_param('http-proxy-user') -%>
subscription-manager config --server.proxy_user='<%= host_param("http-proxy-user") %>'
<% end %>
<% if host_param('http-proxy-password') %>
<% end -%>
<% if host_param('http-proxy-password') -%>
subscription-manager config --server.proxy_password='<%= host_param("http-proxy-password") %>'
<% end %>
<% if host_param('http-proxy-port') %>
<% end -%>
<% if host_param('http-proxy-port') -%>
subscription-manager config --server.proxy_port='<%= host_param("http-proxy-port") %>'
<% end %>
<% end %>
<% end -%>
<% end -%>
<% if host_param('subscription_manager_username') && host_param('subscription_manager_password') %>
<% if host_param('subscription_manager_pool') %>
<% if host_param('subscription_manager_username') && host_param('subscription_manager_password') -%>
<% if host_param('subscription_manager_pool') -%>
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') %>'
<% else %>
<% else -%>
subscription-manager register --name="<%= @host.name %>" --username='<%= host_param("subscription_manager_username") %>' --password='<%= host_param("subscription_manager_password") %>' --auto-attach
<% end %>
<% end -%>
<% elsif activation_key %>
<% elsif activation_key -%>
subscription-manager register --name="<%= @host.name %>" --org='<%= subscription_manager_org %>' --activationkey='<%= activation_key %>'
<% else %>
<% else -%>
echo "No activation key found: Not registering to subscription manager"
<% end %>
<% end -%>
<% if host_param_true?('only_subscription_manager_repos') %>
<% if host_param_true?('only_subscription_manager_repos') -%>
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
Expand All @@ -163,39 +164,39 @@ description: |
fi
fi
done
<% end %>
<% end -%>
<% if host_param_true?('subscription_manager_auto_attach', false) -%>
subscription-manager attach --auto

<% end -%>
<% if host_param('subscription_manager_repos') %>
<% if host_param('subscription_manager_repos') -%>
# workaround for RHEL 6.4 bug https://bugzilla.redhat.com/show_bug.cgi?id=1008016
subscription-manager repos --list > /dev/null
<%= "subscription-manager repos --enable #{host_param('subscription_manager_repos').gsub(/,\s*/, ' --enable ')}" %>
<% end %>
<% end -%>
<% if host_param('subscription_manager_override_repos_cost') %>
<% if host_param('subscription_manager_override_repos_cost') -%>
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
<% end %>
<% end -%>
<% if redhat_install_host_tools %>
<% if redhat_install_host_tools -%>
$PKG_MANAGER_INSTALL katello-host-tools
<% end %>
<% end -%>
<% if redhat_install_host_tracer_tools %>
<% if redhat_install_host_tracer_tools -%>
$PKG_MANAGER_INSTALL katello-host-tools-tracer
<% end %>
<% end %>
<% end -%>
<% end -%>
<% if registration_type == 'spacewalk' %>
<% if registration_type == 'spacewalk' -%>
echo "##############################################################"
echo "################ SPACEWALK REGISTRATION ######################"
echo "##############################################################"

<% if host_param('activation_key') %>
<% if host_param('activation_key') -%>
rhn_activation_key="<%= host_param('activation_key') -%>"
satellite_hostname="<%= host_param('spacewalk_host') -%>"
rhn_cert_file="RHN-ORG-TRUSTED-SSL-CERT"
Expand Down Expand Up @@ -246,7 +247,7 @@ description: |
echo "registration successful."
fi

<% else %>
<% else -%>
echo "No activation key found: Not registering"
<% end %>
<% end %>
<% end -%>
<% end -%>
Expand Up @@ -8,10 +8,9 @@ description: |
The snippet is included in the "global_registration" template and in the "redhat_register" snippet.
The latter ensures host registration during the provisioning process.
-%>

# Select package manager for the OS (sets the $PKG_MANAGER* variables)
if [ -z "$PKG_MANAGER" ]; then
<%= snippet 'pkg_manager' -%>
<%= indent(2) { snippet 'pkg_manager' } -%>
fi

# Define the path to rhsm.conf
Expand Down Expand Up @@ -108,7 +107,7 @@ fi
rhsm_baseurl = "https://cdn.redhat.com"
end
end
%>
-%>

# Configure subscription-manager
test -f $RHSM_CFG.bak || cp $RHSM_CFG $RHSM_CFG.bak
Expand Down
Expand Up @@ -27,23 +27,12 @@ runcmd:
/usr/bin/chronyc -a makestep
/usr/sbin/hwclock --systohc
- |
- |






- |
- |


- |
echo "blacklist amodule" >> /etc/modprobe.d/blacklist.conf

- |
- |

apt-get update
apt-get install -y puppet

Expand Down

0 comments on commit bf03a25

Please sign in to comment.