Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
Fixes #29141 - CloudInit is compatible w/ Kickstart def user data
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Mar 2, 2020
1 parent 03281e9 commit 44546d8
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 34 deletions.
26 changes: 26 additions & 0 deletions provisioning_templates/cloud_init/cloud_init_default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,44 @@ This template accepts the following parameters:
- enable-puppetlabs-puppet6-repo: boolean (default=false)
-%>
<%
rhel_compatible = @host.operatingsystem.family == 'Redhat' && @host.operatingsystem.name != 'Fedora'
pm_set = @host.puppetmaster.empty? ? false : true
proxy_uri = host_param('http-proxy') ? "http://#{host_param('http-proxy')}:#{host_param('http-proxy-port')}" : nil
puppet_enabled = pm_set || host_param_true?('force-puppet')
chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
-%>

#cloud-config
hostname: <%= @host.name %>
fqdn: <%= @host %>
manage_etc_hosts: true
users: {}
runcmd:
- |
<%= indent(2) { snippet 'fix_hosts' } -%>
- |
<%= indent(2) { snippet 'yum_proxy' } -%>
- |
<%= indent(2) { snippet 'ntp' } -%>
- |
<% if rhel_compatible && !host_param_false?('enable-epel') -%>
<%= indent(2) { snippet 'epel' } -%>
<% end -%>
- |
<%= indent(2) { snippet 'redhat_register' } -%>
- |
<% 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 %>
<%= indent(2) { snippet 'chef_client' } %>
<% end -%>
- |
<%=
if puppet_enabled && (host_param_true?('enable-puppetlabs-repo') ||
host_param_true?('enable-puppetlabs-puppet6-repo') ||
Expand Down
15 changes: 4 additions & 11 deletions provisioning_templates/finish/kickstart_default_finish.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ oses:
This template accepts the following parameters:
- bootloader-append: string (default="nofb quiet splash=quiet")
- force-puppet: boolean (default=false)
- ntp-server: string (default="0.fedora.pool.ntp.org")
- use-ntp: boolean (default depends on OS release)
- ntp-server: string (default=undef)
- package_upgrade: boolean (default=true)
- salt_master: string (default=undef)
%>
Expand All @@ -22,7 +23,6 @@ service network restart
<%
rhel_compatible = @host.operatingsystem.family == 'Redhat' && @host.operatingsystem.name != 'Fedora'
pm_set = @host.puppetmaster.empty? ? false : true
proxy_uri = host_param('http-proxy') ? "http://#{host_param('http-proxy')}:#{host_param('http-proxy-port')}" : nil
puppet_enabled = pm_set || host_param_true?('force-puppet')
salt_enabled = host_param('salt_master') ? true : false
chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
Expand All @@ -33,16 +33,9 @@ service network restart
echo 'root:<%= root_pass -%>' | /usr/sbin/chpasswd -e
<% end -%>
<% if proxy_uri -%>
# Yum proxy
echo 'proxy = <%= proxy_uri %>' >> /etc/yum.conf
<% end -%>
<%= snippet 'yum_proxy' %>
#update local time
echo "updating system time"
yum -y install ntpdate
/usr/sbin/ntpdate -sub <%= host_param('ntp-server') || '0.fedora.pool.ntp.org' %>
/usr/sbin/hwclock --systohc
<%= snippet 'ntp' %>
<% if rhel_compatible && !host_param_false?('enable-epel') -%>
<%= snippet 'epel' -%>
Expand Down
16 changes: 3 additions & 13 deletions provisioning_templates/provision/kickstart_default.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This template accepts the following parameters:
- enable-puppetlabs-puppet5-repo: boolean (default=false)
- enable-puppetlabs-puppet6-repo: boolean (default=false)
- salt_master: string (default=undef)
- ntp-server: string (default="0.fedora.pool.ntp.org")
- ntp-server: string (default=undef)
- bootloader-append: string (default="nofb quiet splash=quiet")
- disable-firewall: boolean (default=false)
- package_upgrade: boolean (default=true)
Expand Down Expand Up @@ -213,18 +213,9 @@ exec < /dev/tty3 > /dev/tty3
<%= snippet 'kickstart_networking_setup' %>
<% end -%>
echo "Updating system time"
<% if use_ntp -%>
/usr/sbin/ntpdate -sub <%= host_param('ntp-server') || '0.fedora.pool.ntp.org' %>
<% else -%>
/usr/bin/chronyc makestep
<% end -%>
/usr/sbin/hwclock --systohc
<%= snippet 'ntp' %>
<% if proxy_uri -%>
# Yum proxy
echo 'proxy = <%= proxy_uri %>' >> /etc/yum.conf
<% end -%>
<%= snippet 'yum_proxy' %>
<% if rhel_compatible && !host_param_false?('enable-epel') -%>
<%= snippet 'epel' -%>
Expand Down Expand Up @@ -295,4 +286,3 @@ fi

sync
<%= section_end -%>

31 changes: 31 additions & 0 deletions provisioning_templates/snippet/ntp.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%#
kind: snippet
name: ntp
model: ProvisioningTemplate
snippet: true
%>
<%#
This snippet accepts the following parameters:
- use-ntp: boolean (default depends on OS release)
- ntp-server: string (default=undef)
%>
<%
rhel_compatible = @host.operatingsystem.family == 'Redhat' && @host.operatingsystem.name != 'Fedora'
is_fedora = @host.operatingsystem.name == 'Fedora'
os_major = @host.operatingsystem.major.to_i
use_ntp = host_param_true?('use-ntp') || (is_fedora && os_major < 16) || (rhel_compatible && os_major <= 7)
-%>

echo "Updating system time"
<% if use_ntp -%>
yum -y install ntpdate
<% if host_param('ntp-server') -%>
/usr/sbin/ntpdate -sub <%= host_param('ntp-server') %>
<% end -%>
systemctl enable --now ntpd
<% else -%>
systemctl enable --now chronyd
/usr/bin/chronyc -a makestep
<% end -%>
/usr/sbin/hwclock --systohc
13 changes: 13 additions & 0 deletions provisioning_templates/snippet/yum_proxy.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%#
kind: snippet
name: yum_proxy
model: ProvisioningTemplate
snippet: true
%>
<%
proxy_uri = host_param('http-proxy') ? "http://#{host_param('http-proxy')}:#{host_param('http-proxy-port')}" : nil
-%>
<% if proxy_uri -%>
echo 'proxy = <%= proxy_uri %>' >> /etc/yum.conf
<% end -%>
12 changes: 2 additions & 10 deletions provisioning_templates/user_data/kickstart_default_user_data.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ oses:
rhel_compatible = @host.operatingsystem.family == 'Redhat' && @host.operatingsystem.name != 'Fedora'
# safemode renderer does not support unary negation
pm_set = @host.puppetmaster.empty? ? false : true
proxy_uri = host_param('http-proxy') ? "http://#{host_param('http-proxy')}:#{host_param('http-proxy-port')}" : nil
puppet_enabled = pm_set || host_param_true?('force-puppet')
salt_enabled = host_param('salt_master') ? true : false
chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
Expand All @@ -25,16 +24,9 @@ oses:
echo 'root:<%= root_pass -%>' | /usr/sbin/chpasswd -e
<% end -%>
<% if proxy_uri -%>
# Yum proxy
echo 'proxy = <%= proxy_uri %>' >> /etc/yum.conf
<% end -%>
<%= snippet 'yum_proxy' %>
#update local time
echo "updating system time"
yum -y install ntpdate
/usr/sbin/ntpdate -sub <%= host_param('ntp-server') || '0.fedora.pool.ntp.org' %>
/usr/sbin/hwclock --systohc
<%= snippet 'ntp' %>
<% if rhel_compatible && !host_param_false?('enable-epel') -%>
<%= snippet 'epel' -%>
Expand Down

0 comments on commit 44546d8

Please sign in to comment.