From 6c71cff25e1d884d6c44b153fbe85506781d4e2d Mon Sep 17 00:00:00 2001
From: Amir Forsat <amir.forsat@ess.eu>
Date: Fri, 25 Feb 2022 10:42:55 +0100
Subject: [PATCH] Added support for MCR with custom kernel and initramfs

---
 defaults/main.yml               |  7 +++
 files/ESS-ELREPO.repo.centos7   |  8 +++
 templates/centos7-mcr.ks.j2     | 96 +++++++++++++++++++++++++++++++++
 templates/e1000e.template.j2    |  2 +
 templates/grub-menu/BIOS-MCR.j2 |  2 +
 templates/grub-menu/EFI-MCR.j2  |  2 +
 6 files changed, 117 insertions(+)
 create mode 100644 files/ESS-ELREPO.repo.centos7
 create mode 100644 templates/centos7-mcr.ks.j2
 create mode 100644 templates/e1000e.template.j2
 create mode 100644 templates/grub-menu/BIOS-MCR.j2
 create mode 100644 templates/grub-menu/EFI-MCR.j2

diff --git a/defaults/main.yml b/defaults/main.yml
index 4ea059e..a2dd894 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -23,6 +23,10 @@ live_kernel_version: v1.1.0
 live_kernel_url: "https://artifactory.esss.lu.se/artifactory/list/swi-pkg/centos/centos-live/{{ live_kernel_version }}/"
 live_kernel_path: "{{ tftp_root }}/images/live/"
 
+custom_pxe_version: v0.0.6
+custom_pxe_url: "https://artifactory.esss.lu.se/artifactory/list/swi-pkg/centos/centos-pxe/{{ custom_pxe_version }}/"
+
+
 
 rh_version:
   - centos7
@@ -43,6 +47,7 @@ autoinstall_grub_menus:
   - live_centos
   - proxmox
   - LESS
+  - MCR
 
 # kickstart selection
 autoinstall_default_bootmode: localboot
@@ -80,3 +85,5 @@ autoinstall_kickstart_files:
   - firstboot.sh
   - centos7-thinclient.ks
   - thinclient_packages.template
+  - centos7-mcr.ks
+  - e1000e.template
diff --git a/files/ESS-ELREPO.repo.centos7 b/files/ESS-ELREPO.repo.centos7
new file mode 100644
index 0000000..1f6b2d7
--- /dev/null
+++ b/files/ESS-ELREPO.repo.centos7
@@ -0,0 +1,8 @@
+[elrepo-ess]
+baseurl = https://artifactory.esss.lu.se/artifactory/elrepo/el7/$basearch/
+enabled = 1
+gpgcheck = 0
+#gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
+name = ESS ELREPO 7 RPM repository
+repo_gpgcheck = 0
+
diff --git a/templates/centos7-mcr.ks.j2 b/templates/centos7-mcr.ks.j2
new file mode 100644
index 0000000..0aa146b
--- /dev/null
+++ b/templates/centos7-mcr.ks.j2
@@ -0,0 +1,96 @@
+# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
+# For older versions please use the sample.ks kickstart file.
+
+#platform=x86, AMD64, or Intel EM64T
+# System authorization information
+auth  --useshadow  --enablemd5
+# System bootloader configuration
+bootloader --location=mbr 
+# Partition clearing information
+clearpart --all --initlabel
+# Use text mode install
+text
+# Firewall configuration
+firewall --disabled
+# Run the Setup Agent on first boot
+firstboot --disable
+# System keyboard
+keyboard us
+# System language
+lang en_US
+# Use network installation
+#url --url=http://172.16.14.22/cobbler/ks_mirror/centos7-x86_64
+url --url=https://artifactory.esss.lu.se/artifactory/list/centos-mirror/7/os/x86_64/
+# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
+#repo --name=source-1 --baseurl=http://172.16.14.22/cobbler/ks_mirror/centos7-x86_64
+repo --name=source-1 --baseurl=https://artifactory.esss.lu.se/artifactory/list/centos-mirror/7/os/x86_64/
+
+# Network information
+network --bootproto=dhcp --device=eth0 --onboot=on  
+
+# Reboot after installation
+reboot
+
+#Root password
+rootpw --iscrypted $1$lcr-cobb$ZgH9ugB9zZz7f1KwRZdSB.
+# SELinux configuration
+selinux --permissive
+# Do not configure the X Window System
+skipx
+# System timezone
+timezone  Europe/Stockholm
+# Install OS instead of upgrade
+install
+# Clear the Master Boot Record
+zerombr
+# Allow anaconda to partition the system as needed
+autopart
+
+
+
+
+%pre
+set -x -v
+exec 1>/tmp/ks-pre.log 2>&1
+
+# Once root's homedir is there, copy over the log.
+while : ; do
+    sleep 10
+    if [ -d /mnt/sysimage/root ]; then
+        cp /tmp/ks-pre.log /mnt/sysimage/root/
+        logger "Copied %pre section log to system"
+        break
+    fi
+done &
+
+
+%end
+
+%packages
+
+%include http://172.30.4.71/centos7/default_packages.template
+
+
+%end
+
+%post --nochroot
+set -x -v
+exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1
+
+%end
+
+%post
+set -x -v
+exec 1>/root/ks-post.log 2>&1
+
+%include http://172.30.4.71/centos7/add_repo.template
+%include http://172.30.4.71/centos7/clean_install.template
+%include http://172.30.4.71/centos7/create_csi_user.template
+
+%include http://172.30.4.71/centos7/e1000e.template
+
+%include http://172.30.4.71/centos7/ansible_callback.template
+
+
+%end
+
diff --git a/templates/e1000e.template.j2 b/templates/e1000e.template.j2
new file mode 100644
index 0000000..2576b9b
--- /dev/null
+++ b/templates/e1000e.template.j2
@@ -0,0 +1,2 @@
+wget -O /etc/yum.repos.d/ESS-ELREPO.repo {{ kickstart_url }}/ESS-ELREPO.repo
+yum install -y kmod-e1000e
diff --git a/templates/grub-menu/BIOS-MCR.j2 b/templates/grub-menu/BIOS-MCR.j2
new file mode 100644
index 0000000..d4da81f
--- /dev/null
+++ b/templates/grub-menu/BIOS-MCR.j2
@@ -0,0 +1,2 @@
+linux /images/centos7-x86_64/vmlinuz-custom  ksdevice=bootif lang=  nomodeset text xdriver=vesa kssendmac  ks=http://172.30.4.71/centos7/centos7-mcr.ks noverifyssl inst.sshd=1
+initrd /images/centos7-x86_64/initramfs-custom
diff --git a/templates/grub-menu/EFI-MCR.j2 b/templates/grub-menu/EFI-MCR.j2
new file mode 100644
index 0000000..82357cd
--- /dev/null
+++ b/templates/grub-menu/EFI-MCR.j2
@@ -0,0 +1,2 @@
+linuxefi /images/centos7-x86_64/vmlinuz-custom  ksdevice=bootif lang=  nomodeset text xdriver=vesa kssendmac  ks=http://172.30.4.71/centos7/centos7-mcr.ks noverifyssl inst.sshd=1
+initrdefi /images/centos7-x86_64/initramfs-custom
-- 
GitLab