Skip to content

Commit

Permalink
Fixes #28521 - log location, pre/post, dynamic layout
Browse files Browse the repository at this point in the history
Co-authored-by: Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
  • Loading branch information
lzap and ekohl committed Nov 27, 2020
1 parent 505bee4 commit bb4633b
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<%#
kind: ptable
name: Kickstart dynamic
model: Ptable
oses:
- CentOS
- Fedora
- RedHat
-%>
<%#
When a partition template contains a line starting with "#Dynamic", the contents
will be put into %pre shell scriplet executed with bash and it's expected to
create a file "/tmp/diskpart.cfg" which is then included into the Kickstart
partitioning section. This allows generating partitioning schemes on the
managed node before Anaconda starts installation.
This template is an example of such dynamic partitioning scheme. It follows
recommended scheme of Red Hat Enterprise Linux for servers (no extra allocation
for hibernation):
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-swapspace
Take this as an example, any configuration (RAID, LVM, LUKS) can be created
this way.
-%>
#Dynamic (do not remove this line)

MEMORY=$((`grep MemTotal: /proc/meminfo | sed 's/^MemTotal: *//'|sed 's/ .*//'` / 1024))
if [ "$MEMORY" -lt 2048 ]; then
SWAP_MEMORY=$(($MEMORY * 2))
elif [ "$MEMORY" -lt 8192 ]; then
SWAP_MEMORY=$MEMORY
elif [ "$MEMORY" -lt 65536 ]; then
SWAP_MEMORY=$(($MEMORY / 2))
else
SWAP_MEMORY=32768
fi

cat <<EOF > /tmp/diskpart.cfg
zerombr
clearpart --all --initlabel
part /boot --fstype ext4 --size 200 --asprimary
part swap --size "$SWAP_MEMORY"
part / --fstype ext4 --size 1024 --grow
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ kind: provision
name: Atomic Kickstart default
model: ProvisioningTemplate
%>
<%
rhel_compatible = @host.operatingsystem.family == 'Redhat' && @host.operatingsystem.name != 'Fedora'
is_fedora = @host.operatingsystem.name == 'Fedora'
os_major = @host.operatingsystem.major.to_i
os_minor = @host.operatingsystem.minor.to_i
-%>

lang <%= host_param('lang') || 'en_US.UTF-8' %>
keyboard <%= host_param('keyboard') || 'us' %>
Expand Down Expand Up @@ -42,16 +48,51 @@ rootpw --iscrypted <%= root_pass %>

reboot

<% if @dynamic -%>
# Partition table dynamic generation
%pre --log=/tmp/install.pre.dynamic.log
<%= @host.diskLayout %>
%end
<% end -%>

%pre --log=/tmp/install.pre.custom.log
# Custom pre snippet generated by "<%= template_name + " custom pre" %>"
<%= snippet_if_exists(template_name + " custom pre") %>
%end

# copy %pre log files into chroot
%post --nochroot
cp -vf /tmp/*pre*log /tmp/sysimage/root/
%end

%post
<%= snippet 'redhat_register' %>
rm -f /etc/ostree/remotes.d/*.conf
<%= snippet('remote_execution_ssh_keys') %>
<%= snippet 'efibootmgr_netboot' %>
(
# Report success back to Foreman
<%= snippet 'built' %>
) 2>&1 | tee /mnt/sysimage/root/install.post.log
touch /tmp/foreman_built
%end

%post --log=/root/install.post.custom.log
# Custom post snippet generated by "<%= template_name + " custom post" %>"
<%= snippet_if_exists(template_name + " custom post") %>
%end

exit 0
<%#
The last post section halts Anaconda to prevent endless loop in case HTTP request fails
%>
<% if (is_fedora && os_major < 20) || (rhel_compatible && os_major < 7) -%>
%post
<% else -%>
%post --erroronfail
<% end -%>
if test -f /tmp/foreman_built; then
echo "calling home: build is done!"
<%= indent(2, skip1: true) { snippet('built', :variables => { :endpoint => 'built', :method => 'POST', :body_file => '/root/install.post.log' }) } -%>
else
echo "calling home: build failed!"
<%= indent(2, skip1: true) { snippet('built', :variables => { :endpoint => 'failed', :method => 'POST', :body_file => '/root/install.post.log' }) } -%>
fi

sync
%end
Original file line number Diff line number Diff line change
Expand Up @@ -234,34 +234,29 @@ redhat-lsb-core
<% if host_param_true?('fips_enabled') -%>
<%= snippet 'fips_packages' %>
<% end -%>
<%= section_end -%>
<%= section_end %>
<% if @dynamic -%>
%pre
%pre --log=/tmp/install.pre.dynamic.log
<%= snippet_if_exists(template_name + " custom pre") %>
<%= @host.diskLayout %>
<%= section_end -%>
<%= section_end %>
<% end -%>

%post --nochroot
exec < /dev/tty3 > /dev/tty3
#changing to VT 3 so that we can see whats going on....
%post --nochroot --log=/mnt/sysimage/root/install.postnochroot.log
/usr/bin/chvt 3
(
echo "Changed to TTY3 for post installation..."

<% if host_param_false?('no-resolv-override') -%>
cp -va /etc/resolv.conf /mnt/sysimage/etc/resolv.conf
/usr/bin/chvt 1
) 2>&1 | tee /mnt/sysimage/root/install.postnochroot.log
<%= section_end -%>
<% end -%>
<%= section_end %>
<%#
Main post script, if it fails the last post is still executed.
%>
%post --log=/root/install.post.log
logger "Starting anaconda <%= @host %> postinstall"
exec < /dev/tty3 > /dev/tty3
#changing to VT 3 so that we can see whats going on....
/usr/bin/chvt 3
<%= snippet_if_exists(template_name + " custom post") %>
<%= snippet 'kickstart_networking_setup' %>
<%= snippet 'ntp' %>
Expand Down Expand Up @@ -318,10 +313,20 @@ sed -e 's/DEFAULTKERNEL=kernel-uek/DEFAULTKERNEL=kernel/g' -i /etc/sysconfig/ker
<%= snippet 'insights' -%>
touch /tmp/foreman_built
<%= section_end -%>
<%= section_end %>

# copy %pre log files into chroot
%post --nochroot
cp -vf /tmp/*.pre.*.log /tmp/sysimage/root/
<%= section_end %>

%post --log=/root/install.post.custom.log
# Custom post snippet generated by "<%= template_name + " custom post" %>"
<%= snippet_if_exists(template_name + " custom post") %>
<%= section_end %>
<%#
The last post section halts Anaconda to prevent endless loop
The last post section halts Anaconda to prevent endless loop in case HTTP request fails
%>
<% if (is_fedora && os_major < 20) || (rhel_compatible && os_major < 7) -%>
%post
Expand All @@ -335,11 +340,13 @@ eject -v

if test -f /tmp/foreman_built; then
echo "calling home: build is done!"
<%= indent(2, skip1: true) { snippet('built', :variables => { :endpoint => 'built', :method => 'POST', :body_file => '/mnt/sysimage/root/install.post.log' }) } -%>
<%= indent(2, skip1: true) { snippet('built', :variables => { :endpoint => 'built', :method => 'POST', :body_file => '/root/install.post.log' }) } -%>
else
echo "calling home: build failed!"
<%= indent(2, skip1: true) { snippet('built', :variables => { :endpoint => 'failed', :method => 'POST', :body_file => '/mnt/sysimage/root/install.post.log' }) } -%>
<%= indent(2, skip1: true) { snippet('built', :variables => { :endpoint => 'failed', :method => 'POST', :body_file => '/root/install.post.log' }) } -%>
fi

echo "Changing back to TTY1..."
/usr/bin/chvt 1
sync
<%= section_end -%>
<%= section_end %>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ rootpw --iscrypted xybxa6JUkz63w

reboot


%pre --log=/tmp/install.pre.custom.log
# Custom pre snippet generated by "Atomic Kickstart default custom pre"

%end

# copy %pre log files into chroot
%post --nochroot
cp -vf /tmp/*pre*log /tmp/sysimage/root/
%end

%post


Expand Down Expand Up @@ -56,18 +67,35 @@ rm -f /etc/ostree/remotes.d/*.conf



(
# Report success back to Foreman
if [ -x /usr/bin/curl ]; then
/usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --silent 'http://foreman.some.host.fqdn/unattended/built'
elif [ -x /usr/bin/wget ]; then
/usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/built'
else
wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/built'
fi
touch /tmp/foreman_built
%end

) 2>&1 | tee /mnt/sysimage/root/install.post.log
%post --log=/root/install.post.custom.log
# Custom post snippet generated by "Atomic Kickstart default custom post"

%end

exit 0

%post --erroronfail
if test -f /tmp/foreman_built; then
echo "calling home: build is done!"
if [ -x /usr/bin/curl ]; then
/usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --data @/root/install.post.log --silent 'http://foreman.some.host.fqdn/unattended/built'
elif [ -x /usr/bin/wget ]; then
/usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' --body-file=/root/install.post.log 'http://foreman.some.host.fqdn/unattended/built'
else
wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/built'
fi
else
echo "calling home: build failed!"
if [ -x /usr/bin/curl ]; then
/usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --data @/root/install.post.log --silent 'http://foreman.some.host.fqdn/unattended/failed'
elif [ -x /usr/bin/wget ]; then
/usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' --body-file=/root/install.post.log 'http://foreman.some.host.fqdn/unattended/failed'
else
wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/failed'
fi
fi

sync
%end
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,16 @@ dracut-fips

%end

%post --nochroot
exec < /dev/tty3 > /dev/tty3
#changing to VT 3 so that we can see whats going on....

%post --nochroot --log=/mnt/sysimage/root/install.postnochroot.log
/usr/bin/chvt 3
(
cp -va /etc/resolv.conf /mnt/sysimage/etc/resolv.conf
/usr/bin/chvt 1
) 2>&1 | tee /mnt/sysimage/root/install.postnochroot.log
echo "Changed to TTY3 for post installation..."

%end


%post --log=/root/install.post.log
logger "Starting anaconda snapshothost postinstall"
exec < /dev/tty3 > /dev/tty3
#changing to VT 3 so that we can see whats going on....
/usr/bin/chvt 3




Expand Down Expand Up @@ -175,28 +169,41 @@ EOF
touch /tmp/foreman_built
%end

# copy %pre log files into chroot
%post --nochroot
cp -vf /tmp/*.pre.*.log /tmp/sysimage/root/
%end

%post --log=/root/install.post.custom.log
# Custom post snippet generated by "Kickstart default custom post"

%end


%post --erroronfail


if test -f /tmp/foreman_built; then
echo "calling home: build is done!"
if [ -x /usr/bin/curl ]; then
/usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --data @/mnt/sysimage/root/install.post.log --silent 'http://foreman.some.host.fqdn/unattended/built'
/usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --data @/root/install.post.log --silent 'http://foreman.some.host.fqdn/unattended/built'
elif [ -x /usr/bin/wget ]; then
/usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' --body-file=/mnt/sysimage/root/install.post.log 'http://foreman.some.host.fqdn/unattended/built'
/usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' --body-file=/root/install.post.log 'http://foreman.some.host.fqdn/unattended/built'
else
wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/built'
fi
else
echo "calling home: build failed!"
if [ -x /usr/bin/curl ]; then
/usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --data @/mnt/sysimage/root/install.post.log --silent 'http://foreman.some.host.fqdn/unattended/failed'
/usr/bin/curl -o /dev/null --noproxy \* -H 'Content-Type: text/plain' --data @/root/install.post.log --silent 'http://foreman.some.host.fqdn/unattended/failed'
elif [ -x /usr/bin/wget ]; then
/usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' --body-file=/mnt/sysimage/root/install.post.log 'http://foreman.some.host.fqdn/unattended/failed'
/usr/bin/wget -q -O /dev/null --no-proxy --method POST --header 'Content-Type: text/plain' --body-file=/root/install.post.log 'http://foreman.some.host.fqdn/unattended/failed'
else
wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.some.host.fqdn/unattended/failed'
fi
fi

echo "Changing back to TTY1..."
/usr/bin/chvt 1
sync
%end
%end

0 comments on commit bb4633b

Please sign in to comment.