From 0ca4de95823308f83a8c3b755331320b50bd223b Mon Sep 17 00:00:00 2001 From: Alexsander de Souza <61709370+alexsander-souza@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:45:35 -0300 Subject: [PATCH] Use packer templatefile (#211) fixes #188, #197 --- centos6/Makefile | 11 +-- centos6/README.md | 2 +- centos6/centos6.pkr.hcl | 66 ++++++++++++++++- .../{centos6.ks.in => centos6.ks.pkrtpl.hcl} | 12 ++-- centos8-stream/Makefile | 11 +-- centos8-stream/README.md | 2 +- centos8-stream/centos8-stream.pkr.hcl | 52 +++++++++++++- centos8-stream/http/centos8-stream.ks.in | 71 ------------------ .../http/centos8-stream.ks.pkrtpl.hcl | 6 +- centos8/Makefile | 11 +-- centos8/README.md | 2 +- centos8/centos8.pkr.hcl | 51 ++++++++++++- centos8/http/centos8.ks.pkrtpl.hcl | 71 ++++++++++++++++++ centos9-stream/Makefile | 11 +-- centos9-stream/README.md | 2 +- centos9-stream/centos9-stream.pkr.hcl | 67 +++++++++++++++-- centos9-stream/http/centos9-stream.ks.in | 72 ------------------- .../http/centos9-stream.ks.pkrtpl.hcl | 72 +++++++++++++++++++ ol8/Makefile | 11 +-- ol8/README.md | 3 +- ol8/http/{ol8.ks.in => ol8.ks.pkrtpl.hcl} | 4 +- ol8/ol8.pkr.hcl | 44 +++++++++++- ol9/Makefile | 11 +-- ol9/README.md | 3 +- ol9/http/{ol9.ks.in => ol9.ks.pkrtpl.hcl} | 4 +- ol9/ol9.pkr.hcl | 44 +++++++++++- rhel7/Makefile | 11 +-- rhel7/README.md | 2 +- .../http/{rhel7.ks.in => rhel7.ks.pkrtpl.hcl} | 4 +- rhel7/rhel7.pkr.hcl | 37 +++++++++- rhel8/Makefile | 11 +-- rhel8/README.md | 2 +- .../http/rhel8.ks.pkrtpl.hcl | 2 +- rhel8/rhel8.pkr.hcl | 30 +++++++- rhel9/Makefile | 11 +-- rhel9/README.md | 2 +- .../http/rhel9.ks.pkrtpl.hcl | 2 +- rhel9/rhel9.pkr.hcl | 30 +++++++- rocky9/Makefile | 11 +-- rocky9/README.md | 2 +- .../http/{rocky.ks.in => rocky.ks.pkrtpl.hcl} | 8 +-- rocky9/rocky9.pkr.hcl | 59 ++++++++++++++- sles12/README.md | 8 --- 43 files changed, 653 insertions(+), 295 deletions(-) rename centos6/http/{centos6.ks.in => centos6.ks.pkrtpl.hcl} (76%) delete mode 100644 centos8-stream/http/centos8-stream.ks.in rename centos8/http/centos8.ks.in => centos8-stream/http/centos8-stream.ks.pkrtpl.hcl (86%) create mode 100644 centos8/http/centos8.ks.pkrtpl.hcl delete mode 100644 centos9-stream/http/centos9-stream.ks.in create mode 100644 centos9-stream/http/centos9-stream.ks.pkrtpl.hcl rename ol8/http/{ol8.ks.in => ol8.ks.pkrtpl.hcl} (89%) rename ol9/http/{ol9.ks.in => ol9.ks.pkrtpl.hcl} (89%) rename rhel7/http/{rhel7.ks.in => rhel7.ks.pkrtpl.hcl} (91%) rename rhel9/http/rhel9.ks.in => rhel8/http/rhel8.ks.pkrtpl.hcl (96%) rename rhel8/http/rhel8.ks.in => rhel9/http/rhel9.ks.pkrtpl.hcl (96%) rename rocky9/http/{rocky.ks.in => rocky.ks.pkrtpl.hcl} (85%) diff --git a/centos6/Makefile b/centos6/Makefile index bf742dfa..bbe0c5ee 100644 --- a/centos6/Makefile +++ b/centos6/Makefile @@ -5,7 +5,7 @@ include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -13,13 +13,8 @@ all: centos6.tar.gz $(eval $(call check_packages_deps)) -centos6.tar.gz: check-deps clean http/centos6.ks +centos6.tar.gz: check-deps clean ${PACKER} init centos6.pkr.hcl && ${PACKER} build centos6.pkr.hcl -http/centos6.ks: http/centos6.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-centos6 centos6.tar.gz http/centos6.ks - -.INTERMEDIATE: http/centos6.ks + ${RM} -rf output-centos6 centos6.tar.gz diff --git a/centos6/README.md b/centos6/README.md index 27364b62..89e0f001 100644 --- a/centos6/README.md +++ b/centos6/README.md @@ -30,7 +30,7 @@ To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image diff --git a/centos6/centos6.pkr.hcl b/centos6/centos6.pkr.hcl index d3901b9e..a0effd08 100644 --- a/centos6/centos6.pkr.hcl +++ b/centos6/centos6.pkr.hcl @@ -24,18 +24,77 @@ variable "centos6_sha256sum_url" { default = "https://mirrors.edge.kernel.org/centos/6.10/isos/x86_64/sha256sum.txt" } +# use can use "--url" to specify the exact url for os repo +variable "ks_os_repos" { + type = string + default = "--url='http://mirror.centos.org/centos/6/os/x86_64'" +} + +# Use --baseurl to specify the exact url for updates repo +variable "ks_updates_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=updates'" +} + +# Use --baseurl to specify the exact url for extras repo +variable "ks_extras_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=extras'" +} + +# Use --baseurl to specify the exact url for EPEL6 repo +variable "ks_epel6_repos" { + type = string + default = "--mirrorlist='https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64'" +} + +# Use --baseurl to specify the exact url for EPEL6 repo +variable "ks_cloudinit_repos" { + type = string + default = "--baseurl='http://copr-be.cloud.fedoraproject.org/results/@cloud-init/el-stable/epel-6-x86_64'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +variable ks_mirror { + type = string + default = "${env("KS_MIRROR")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" + ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/os/x86_64" : var.ks_os_repos + ks_updates_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/updates/x86_64" : var.ks_updates_repos + ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/x86_64" : var.ks_extras_repos +} + source "qemu" "centos6" { boot_command = [" ", "ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "file:${var.centos6_sha256sum_url}" iso_url = var.centos6_iso_url memory = 2048 qemuargs = [["-serial", "stdio"]] shutdown_timeout = "1h" + http_content = { + "/centos6.ks" = templatefile("${path.root}/http/centos6.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_OS_REPOS = local.ks_os_repos, + KS_UPDATES_REPOS = local.ks_updates_repos, + KS_EXTRAS_REPOS = local.ks_extras_repos + KS_EPEL6_REPOS = var.ks_epel6_repos + KS_CLOUDINIT_REPOS = var.ks_cloudinit_repos + } + ) + } + } build { @@ -43,10 +102,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=centos6", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/centos6/http/centos6.ks.in b/centos6/http/centos6.ks.pkrtpl.hcl similarity index 76% rename from centos6/http/centos6.ks.in rename to centos6/http/centos6.ks.pkrtpl.hcl index bec969e4..a5050229 100644 --- a/centos6/http/centos6.ks.in +++ b/centos6/http/centos6.ks.pkrtpl.hcl @@ -1,4 +1,4 @@ -url --url="http://mirror.centos.org/centos/6/os/x86_64" ${KS_PROXY} +url ${KS_OS_REPOS} ${KS_PROXY} poweroff firewall --enabled --service=ssh firstboot --disable @@ -12,17 +12,17 @@ timezone UTC --isUtc bootloader --location=mbr --driveorder="vda" --timeout=1 rootpw --plaintext password -repo --name="Updates" --mirrorlist="http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=updates" ${KS_PROXY} -repo --name="Extras" --mirrorlist="http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=extras" ${KS_PROXY} -repo --name="EPEL6" --mirrorlist="https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64" ${KS_PROXY} +repo --name="Updates" ${KS_UPDATES_REPOS} ${KS_PROXY} +repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY} +repo --name="EPEL6" ${KS_EPEL6_REPOS} ${KS_PROXY} # CentOS 6 requires a newer version of cloud-init to use advanced features with MAAS. -repo --name="cloud-init" --baseurl="http://copr-be.cloud.fedoraproject.org/results/@cloud-init/el-stable/epel-6-x86_64" ${KS_PROXY} +repo --name="cloud-init" ${KS_CLOUDINIT_REPOS} ${KS_PROXY} zerombr clearpart --all --initlabel part / --size=1 --grow --asprimary --fstype=ext4 -%post --erroronfai +%post --erroronfail # workaround anaconda requirements and clear root password passwd -d root passwd -l root diff --git a/centos8-stream/Makefile b/centos8-stream/Makefile index ead8ad60..cc1efed0 100644 --- a/centos8-stream/Makefile +++ b/centos8-stream/Makefile @@ -5,7 +5,7 @@ include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -13,13 +13,8 @@ all: centos8-stream.tar.gz $(eval $(call check_packages_deps)) -centos8-stream.tar.gz: check-deps clean http/centos8-stream.ks +centos8-stream.tar.gz: check-deps clean ${PACKER} init centos8-stream.pkr.hcl && ${PACKER} build centos8-stream.pkr.hcl -http/centos8-stream.ks: http/centos8-stream.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-centos8-stream centos8-stream.tar.gz http/centos8-stream.ks - -.INTERMEDIATE: http/centos8-stream.ks + ${RM} -rf output-centos8-stream centos8-stream.tar.gz diff --git a/centos8-stream/README.md b/centos8-stream/README.md index 88bdefb0..7560ef55 100644 --- a/centos8-stream/README.md +++ b/centos8-stream/README.md @@ -35,7 +35,7 @@ To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image diff --git a/centos8-stream/centos8-stream.pkr.hcl b/centos8-stream/centos8-stream.pkr.hcl index 9e6d46b8..e3ec0bea 100644 --- a/centos8-stream/centos8-stream.pkr.hcl +++ b/centos8-stream/centos8-stream.pkr.hcl @@ -24,18 +24,63 @@ variable "centos8_stream_sha256sum_url" { default = "https://mirrors.edge.kernel.org/centos/8-stream/isos/x86_64/CHECKSUM" } +# use can use "--url" to specify the exact url for os repo +variable "ks_os_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=BaseOS'" +} + +# Use --baseurl to specify the exact url for AppStream repo +variable "ks_appstream_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=AppStream'" +} + +# Use --baseurl to specify the exact url for extras repo +variable "ks_extras_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=extras'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +variable ks_mirror { + type = string + default = "${env("KS_MIRROR")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" + ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/os/x86_64" : var.ks_os_repos + ks_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/AppStream/x86_64" : var.ks_appstream_repos + ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/x86_64" : var.ks_extras_repos +} + source "qemu" "centos8-stream" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos8-stream.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "file:${var.centos8_stream_sha256sum_url}" iso_url = var.centos8_stream_iso_url memory = 2048 qemuargs = [["-serial", "stdio"]] shutdown_timeout = "1h" + http_content = { + "/centos8-stream.ks" = templatefile("${path.root}/http/centos8-stream.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_OS_REPOS = local.ks_os_repos, + KS_APPSTREAM_REPOS = local.ks_appstream_repos, + KS_EXTRAS_REPOS = local.ks_extras_repos + } + ) + } + } build { @@ -43,10 +88,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=centos8-stream", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/centos8-stream/http/centos8-stream.ks.in b/centos8-stream/http/centos8-stream.ks.in deleted file mode 100644 index 823e78b0..00000000 --- a/centos8-stream/http/centos8-stream.ks.in +++ /dev/null @@ -1,71 +0,0 @@ -url --mirrorlist="http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=BaseOS" ${KS_PROXY} -poweroff -firewall --enabled --service=ssh -firstboot --disable -ignoredisk --only-use=vda -lang en_US.UTF-8 -keyboard us -network --device eth0 --bootproto=dhcp -firewall --enabled --service=ssh -selinux --enforcing -timezone UTC --isUtc -bootloader --location=mbr --driveorder="vda" --timeout=1 -rootpw --plaintext password - -repo --name="AppStream" --mirrorlist="http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=AppStream" ${KS_PROXY} -repo --name="Extras" --mirrorlist="http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=extras" ${KS_PROXY} - -zerombr -clearpart --all --initlabel -part / --size=1 --grow --asprimary --fstype=ext4 - -%post --erroronfail -# workaround anaconda requirements and clear root password -passwd -d root -passwd -l root - -# Clean up install config not applicable to deployed environments. -for f in resolv.conf fstab; do - rm -f /etc/$f - touch /etc/$f - chown root:root /etc/$f - chmod 644 /etc/$f -done - -rm -f /etc/sysconfig/network-scripts/ifcfg-[^lo]* - -# Kickstart copies install boot options. Serial is turned on for logging with -# Packer which disables console output. Disable it so console output is shown -# during deployments -sed -i 's/^GRUB_TERMINAL=.*/GRUB_TERMINAL_OUTPUT="console"/g' /etc/default/grub -sed -i '/GRUB_SERIAL_COMMAND="serial"/d' /etc/default/grub -sed -ri 's/(GRUB_CMDLINE_LINUX=".*)\s+console=ttyS0(.*")/\1\2/' /etc/default/grub -sed -i 's/GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/g' /etc/default/grub - -dnf clean all -%end - -%packages -@core -bash-completion -cloud-init -# cloud-init only requires python3-oauthlib with MAAS. As such upstream -# removed this dependency. -python3-oauthlib -rsync -tar -# grub2-efi-x64 ships grub signed for UEFI secure boot. If grub2-efi-x64-modules -# is installed grub will be generated on deployment and unsigned which breaks -# UEFI secure boot. -grub2-efi-x64 -efibootmgr -shim-x64 -dosfstools -lvm2 -mdadm -device-mapper-multipath -iscsi-initiator-utils --plymouth -# Remove Intel wireless firmware --i*-firmware -%end diff --git a/centos8/http/centos8.ks.in b/centos8-stream/http/centos8-stream.ks.pkrtpl.hcl similarity index 86% rename from centos8/http/centos8.ks.in rename to centos8-stream/http/centos8-stream.ks.pkrtpl.hcl index 80800618..bb04f06c 100644 --- a/centos8/http/centos8.ks.in +++ b/centos8-stream/http/centos8-stream.ks.pkrtpl.hcl @@ -1,4 +1,4 @@ -url --mirrorlist="${KS_MIRROR}/?release=8&arch=x86_64&repo=BaseOS" ${KS_PROXY} +url ${KS_OS_REPOS} ${KS_PROXY} poweroff firewall --enabled --service=ssh firstboot --disable @@ -12,8 +12,8 @@ timezone UTC --isUtc bootloader --location=mbr --driveorder="vda" --timeout=1 rootpw --plaintext password -repo --name="AppStream" --mirrorlist="${KS_MIRROR}/?release=8&arch=x86_64&repo=AppStream" ${KS_PROXY} -repo --name="Extras" --mirrorlist="${KS_MIRROR}/?release=8&arch=x86_64&repo=extras" ${KS_PROXY} +repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY} +repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY} zerombr clearpart --all --initlabel diff --git a/centos8/Makefile b/centos8/Makefile index c1595a0c..8c2c11e0 100644 --- a/centos8/Makefile +++ b/centos8/Makefile @@ -5,7 +5,7 @@ include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 KS_MIRROR ?= http://mirrorlist.centos.org -export PACKER_LOG KS_PROXY KS_MIRROR +export PACKER_LOG .PHONY: all clean @@ -13,13 +13,8 @@ all: centos8.tar.gz $(eval $(call check_packages_deps)) -centos8.tar.gz: check-deps clean http/centos8.ks +centos8.tar.gz: check-deps clean ${PACKER} init centos8.pkr.hcl && ${PACKER} build centos8.pkr.hcl -http/centos8.ks: http/centos8.ks.in - envsubst '$${KS_PROXY} $${KS_MIRROR}' < $< | tee $@ - clean: - ${RM} -rf output-centos8 centos8.tar.gz http/centos8.ks - -.INTERMEDIATE: http/centos8.ks + ${RM} -rf output-centos8 centos8.tar.gz diff --git a/centos8/README.md b/centos8/README.md index 110c06c0..926d94f0 100644 --- a/centos8/README.md +++ b/centos8/README.md @@ -35,7 +35,7 @@ To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image diff --git a/centos8/centos8.pkr.hcl b/centos8/centos8.pkr.hcl index acb9ac35..a491645d 100644 --- a/centos8/centos8.pkr.hcl +++ b/centos8/centos8.pkr.hcl @@ -24,18 +24,62 @@ variable "centos8_sha256sum_url" { default = "https://mirrors.edge.kernel.org/centos/8.4.2105/isos/x86_64/CHECKSUM" } +# use can use "--url" to specify the exact url for BaseOS repo +variable "ks_os_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=BaseOS'" +} + +# Use --baseurl to specify the exact url for AppStream repo +variable "ks_appstream_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream'" +} + +# Use --baseurl to specify the exact url for extras repo +variable "ks_extras_repos" { + type = string + default = "--mirrorlist='http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=extras'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +variable ks_mirror { + type = string + default = "${env("KS_MIRROR")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" + ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/os/x86_64" : var.ks_os_repos + ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/x86_64" : var.ks_extras_repos +} + source "qemu" "centos8" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos8.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "file:${var.centos8_sha256sum_url}" iso_url = var.centos8_iso_url memory = 2048 qemuargs = [["-serial", "stdio"]] shutdown_timeout = "1h" + http_content = { + "/centos8.ks" = templatefile("${path.root}/http/centos7.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_OS_REPOS = local.ks_os_repos, + KS_APPSTREAM_REPOS = var.ks_appstream_repos, + KS_EXTRAS_REPOS = local.ks_extras_repos + } + ) + } + } build { @@ -43,10 +87,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=centos8", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/centos8/http/centos8.ks.pkrtpl.hcl b/centos8/http/centos8.ks.pkrtpl.hcl new file mode 100644 index 00000000..bb04f06c --- /dev/null +++ b/centos8/http/centos8.ks.pkrtpl.hcl @@ -0,0 +1,71 @@ +url ${KS_OS_REPOS} ${KS_PROXY} +poweroff +firewall --enabled --service=ssh +firstboot --disable +ignoredisk --only-use=vda +lang en_US.UTF-8 +keyboard us +network --device eth0 --bootproto=dhcp +firewall --enabled --service=ssh +selinux --enforcing +timezone UTC --isUtc +bootloader --location=mbr --driveorder="vda" --timeout=1 +rootpw --plaintext password + +repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY} +repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY} + +zerombr +clearpart --all --initlabel +part / --size=1 --grow --asprimary --fstype=ext4 + +%post --erroronfail +# workaround anaconda requirements and clear root password +passwd -d root +passwd -l root + +# Clean up install config not applicable to deployed environments. +for f in resolv.conf fstab; do + rm -f /etc/$f + touch /etc/$f + chown root:root /etc/$f + chmod 644 /etc/$f +done + +rm -f /etc/sysconfig/network-scripts/ifcfg-[^lo]* + +# Kickstart copies install boot options. Serial is turned on for logging with +# Packer which disables console output. Disable it so console output is shown +# during deployments +sed -i 's/^GRUB_TERMINAL=.*/GRUB_TERMINAL_OUTPUT="console"/g' /etc/default/grub +sed -i '/GRUB_SERIAL_COMMAND="serial"/d' /etc/default/grub +sed -ri 's/(GRUB_CMDLINE_LINUX=".*)\s+console=ttyS0(.*")/\1\2/' /etc/default/grub +sed -i 's/GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/g' /etc/default/grub + +dnf clean all +%end + +%packages +@core +bash-completion +cloud-init +# cloud-init only requires python3-oauthlib with MAAS. As such upstream +# removed this dependency. +python3-oauthlib +rsync +tar +# grub2-efi-x64 ships grub signed for UEFI secure boot. If grub2-efi-x64-modules +# is installed grub will be generated on deployment and unsigned which breaks +# UEFI secure boot. +grub2-efi-x64 +efibootmgr +shim-x64 +dosfstools +lvm2 +mdadm +device-mapper-multipath +iscsi-initiator-utils +-plymouth +# Remove Intel wireless firmware +-i*-firmware +%end diff --git a/centos9-stream/Makefile b/centos9-stream/Makefile index 0c056f2c..709fcb80 100644 --- a/centos9-stream/Makefile +++ b/centos9-stream/Makefile @@ -5,7 +5,7 @@ include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -13,13 +13,8 @@ all: centos9-stream.tar.gz $(eval $(call check_packages_deps)) -centos9-stream.tar.gz: check-deps clean http/centos9-stream.ks +centos9-stream.tar.gz: check-deps clean ${PACKER} init centos9-stream.pkr.hcl && ${PACKER} build centos9-stream.pkr.hcl -http/centos9-stream.ks: http/centos9-stream.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-centos9-stream centos9-stream.tar.gz http/centos9-stream.ks - -.INTERMEDIATE: http/centos9-stream.ks + ${RM} -rf output-centos9-stream centos9-stream.tar.gz diff --git a/centos9-stream/README.md b/centos9-stream/README.md index 4082e348..48e2c503 100644 --- a/centos9-stream/README.md +++ b/centos9-stream/README.md @@ -34,7 +34,7 @@ To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image diff --git a/centos9-stream/centos9-stream.pkr.hcl b/centos9-stream/centos9-stream.pkr.hcl index ce1e940e..18f312ae 100644 --- a/centos9-stream/centos9-stream.pkr.hcl +++ b/centos9-stream/centos9-stream.pkr.hcl @@ -19,18 +19,76 @@ variable "centos9_stream_iso_url" { default = "https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-boot.iso" } +variable "centos9_stream_sha256sum_url" { + type = string + default = "none" +} + +# use can use "--url" to specify the exact url for os repo +variable "ks_os_repos" { + type = string + default = "--mirrorlist='https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http'" +} + +# use can use "--url" to specify the exact url for baseOS repo +variable "ks_baseos_repos" { + type = string + default = "--metalink='https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http'" +} + +# Use --baseurl to specify the exact url for AppStream repo +variable "ks_appstream_repos" { + type = string + default = "--metalink='https://mirrors.centos.org/metalink?repo=centos-appstream-9-stream&arch=x86_64&protocol=https,http'" +} + +# Use --baseurl to specify the exact url for centos repo +variable "ks_centos_repos" { + type = string + default = "--metalink='https://mirrors.centos.org/metalink?repo=centos-crb-9-stream&arch=x86_64&protocol=https,http'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +variable ks_mirror { + type = string + default = "${env("KS_MIRROR")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" + ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/BaseOS/x86_64" : var.ks_os_repos + ks_baseos_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/BaseOS/x86_64" : var.ks_baseos_repos + ks_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/AppStream/x86_64" : var.ks_appstream_repos + ks_centos_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/CRB/x86_64" : var.ks_centos_repos +} + source "qemu" "centos9-stream" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos9-stream.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" - iso_checksum = "none" + iso_checksum = var.centos9_stream_sha256sum_url iso_url = var.centos9_stream_iso_url memory = 2048 qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] shutdown_timeout = "1h" + http_content = { + "/centos9-stream.ks" = templatefile("${path.root}/http/centos9-stream.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_OS_REPOS = local.ks_os_repos, + KS_BASEOS_REPOS = local.ks_baseos_repos, + KS_APPSTREAM_REPOS = local.ks_appstream_repos, + KS_CENTOS_REPOS = local.ks_centos_repos + } + ) + } + } build { @@ -38,10 +96,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=centos9-stream", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/centos9-stream/http/centos9-stream.ks.in b/centos9-stream/http/centos9-stream.ks.in deleted file mode 100644 index b21042fe..00000000 --- a/centos9-stream/http/centos9-stream.ks.in +++ /dev/null @@ -1,72 +0,0 @@ -url --mirrorlist=https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http ${KS_PROXY} -poweroff -firewall --enabled --service=ssh -firstboot --disable -ignoredisk --only-use=vda -lang en_US.UTF-8 -keyboard us -network --device eth0 --bootproto=dhcp -firewall --enabled --service=ssh -selinux --enforcing -timezone UTC --isUtc -bootloader --location=mbr --driveorder="vda" --timeout=1 -rootpw --plaintext password - -repo --name=baseos --metalink=https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http ${KS_PROXY} -repo --name=appstream --metalink=https://mirrors.centos.org/metalink?repo=centos-appstream-9-stream&arch=x86_64&protocol=https,http ${KS_PROXY} -repo --name=centos --metalink=https://mirrors.centos.org/metalink?repo=centos-crb-9-stream&arch=x86_64&protocol=https,http ${KS_PROXY} - -zerombr -clearpart --all --initlabel -part / --size=1 --grow --asprimary --fstype=ext4 - -%post --erroronfail -# workaround anaconda requirements and clear root password -passwd -d root -passwd -l root - -# Clean up install config not applicable to deployed environments. -for f in resolv.conf fstab; do - rm -f /etc/$f - touch /etc/$f - chown root:root /etc/$f - chmod 644 /etc/$f -done - -rm -f /etc/sysconfig/network-scripts/ifcfg-[^lo]* - -# Kickstart copies install boot options. Serial is turned on for logging with -# Packer which disables console output. Disable it so console output is shown -# during deployments -sed -i 's/^GRUB_TERMINAL=.*/GRUB_TERMINAL_OUTPUT="console"/g' /etc/default/grub -sed -i '/GRUB_SERIAL_COMMAND="serial"/d' /etc/default/grub -sed -ri 's/(GRUB_CMDLINE_LINUX=".*)\s+console=ttyS0(.*")/\1\2/' /etc/default/grub -sed -i 's/GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/g' /etc/default/grub - -dnf clean all -%end - -%packages -@core -bash-completion -cloud-init -# cloud-init only requires python3-oauthlib with MAAS. As such upstream -# removed this dependency. -python3-oauthlib -rsync -tar -# grub2-efi-x64 ships grub signed for UEFI secure boot. If grub2-efi-x64-modules -# is installed grub will be generated on deployment and unsigned which breaks -# UEFI secure boot. -grub2-efi-x64 -efibootmgr -shim-x64 -dosfstools -lvm2 -mdadm -device-mapper-multipath -iscsi-initiator-utils --plymouth -# Remove Intel wireless firmware --i*-firmware -%end diff --git a/centos9-stream/http/centos9-stream.ks.pkrtpl.hcl b/centos9-stream/http/centos9-stream.ks.pkrtpl.hcl new file mode 100644 index 00000000..d609a915 --- /dev/null +++ b/centos9-stream/http/centos9-stream.ks.pkrtpl.hcl @@ -0,0 +1,72 @@ +url ${KS_OS_REPOS} ${KS_PROXY} +poweroff +firewall --enabled --service=ssh +firstboot --disable +ignoredisk --only-use=vda +lang en_US.UTF-8 +keyboard us +network --device eth0 --bootproto=dhcp +firewall --enabled --service=ssh +selinux --enforcing +timezone UTC --isUtc +bootloader --location=mbr --driveorder="vda" --timeout=1 +rootpw --plaintext password + +repo --name=baseos ${KS_BASEOS_REPOS} ${KS_PROXY} +repo --name=appstream ${KS_APPSTREAM_REPOS} ${KS_PROXY} +repo --name=centos ${KS_CENTOS_REPOS} ${KS_PROXY} + +zerombr +clearpart --all --initlabel +part / --size=1 --grow --asprimary --fstype=ext4 + +%post --erroronfail +# workaround anaconda requirements and clear root password +passwd -d root +passwd -l root + +# Clean up install config not applicable to deployed environments. +for f in resolv.conf fstab; do + rm -f /etc/$f + touch /etc/$f + chown root:root /etc/$f + chmod 644 /etc/$f +done + +rm -f /etc/sysconfig/network-scripts/ifcfg-[^lo]* + +# Kickstart copies install boot options. Serial is turned on for logging with +# Packer which disables console output. Disable it so console output is shown +# during deployments +sed -i 's/^GRUB_TERMINAL=.*/GRUB_TERMINAL_OUTPUT="console"/g' /etc/default/grub +sed -i '/GRUB_SERIAL_COMMAND="serial"/d' /etc/default/grub +sed -ri 's/(GRUB_CMDLINE_LINUX=".*)\s+console=ttyS0(.*")/\1\2/' /etc/default/grub +sed -i 's/GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/g' /etc/default/grub + +dnf clean all +%end + +%packages +@core +bash-completion +cloud-init +# cloud-init only requires python3-oauthlib with MAAS. As such upstream +# removed this dependency. +python3-oauthlib +rsync +tar +# grub2-efi-x64 ships grub signed for UEFI secure boot. If grub2-efi-x64-modules +# is installed grub will be generated on deployment and unsigned which breaks +# UEFI secure boot. +grub2-efi-x64 +efibootmgr +shim-x64 +dosfstools +lvm2 +mdadm +device-mapper-multipath +iscsi-initiator-utils +-plymouth +# Remove Intel wireless firmware +-i*-firmware +%end diff --git a/ol8/Makefile b/ol8/Makefile index 29befead..61f97c02 100644 --- a/ol8/Makefile +++ b/ol8/Makefile @@ -5,7 +5,7 @@ include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -13,13 +13,8 @@ all: ol8.tar.gz $(eval $(call check_packages_deps)) -ol8.tar.gz: check-deps clean http/ol8.ks +ol8.tar.gz: check-deps clean ${PACKER} init ol8.pkr.hcl && ${PACKER} build ol8.pkr.hcl -http/ol8.ks: http/ol8.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-ol8 ol8.tar.gz http/ol8.ks - -.INTERMEDIATE: http/ol8.ks + ${RM} -rf output-ol8 ol8.tar.gz diff --git a/ol8/README.md b/ol8/README.md index a02a66ea..42dc0286 100644 --- a/ol8/README.md +++ b/ol8/README.md @@ -30,7 +30,7 @@ To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image @@ -46,7 +46,6 @@ be in packer-maas/ol8, where this file is located. Once in packer-maas/ol8 you can generate an image with: ```shell -envsubst '$${KS_PROXY}' < http/ol8.ks.in | tee http/ol8.ks packer init . PACKER_LOG=1 packer build . ``` diff --git a/ol8/http/ol8.ks.in b/ol8/http/ol8.ks.pkrtpl.hcl similarity index 89% rename from ol8/http/ol8.ks.in rename to ol8/http/ol8.ks.pkrtpl.hcl index f60d9fc0..89d4a6e2 100644 --- a/ol8/http/ol8.ks.in +++ b/ol8/http/ol8.ks.pkrtpl.hcl @@ -1,4 +1,4 @@ -url --url="https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64" ${KS_PROXY} +url ${KS_OS_REPOS} ${KS_PROXY} poweroff firstboot --disable ignoredisk --only-use=vda @@ -11,7 +11,7 @@ timezone UTC --utc bootloader --location=mbr --driveorder="vda" --timeout=1 rootpw --plaintext password -repo --name="ol8_AppStream" --baseurl="https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/" ${KS_PROXY} +repo --name="ol8_AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY} zerombr clearpart --all --initlabel diff --git a/ol8/ol8.pkr.hcl b/ol8/ol8.pkr.hcl index 7ac05ae4..b678c18f 100644 --- a/ol8/ol8.pkr.hcl +++ b/ol8/ol8.pkr.hcl @@ -24,18 +24,55 @@ variable "ol8_sha256sum_path" { default = "https://linux.oracle.com/security/gpg/checksum/OracleLinux-R8-U8-Server-x86_64.checksum" } +# use can use "--url" to specify the exact url for os repo +variable "ks_os_repos" { + type = string + default = "--url='https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64'" +} + +# Use --baseurl to specify the exact url for AppStream repo +variable "ks_appstream_repos" { + type = string + default = "--baseurl='https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +variable ks_mirror { + type = string + default = "${env("KS_MIRROR")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" + ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/baseos/latest/x86_64" : var.ks_os_repos + ks_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/appstream/x86_64/" : var.ks_appstream_repos +} + source "qemu" "ol8" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ol8.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "file:${var.ol8_sha256sum_path}" iso_url = var.ol8_iso_url memory = 2048 qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] shutdown_timeout = "1h" + http_content = { + "/ol8.ks" = templatefile("${path.root}/http/ol8.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_OS_REPOS = local.ks_os_repos, + KS_APPSTREAM_REPOS = local.ks_appstream_repos, + } + ) + } + } build { @@ -43,10 +80,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=ol8", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/ol9/Makefile b/ol9/Makefile index 73e5a311..44b6bcfc 100644 --- a/ol9/Makefile +++ b/ol9/Makefile @@ -5,7 +5,7 @@ include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -13,13 +13,8 @@ all: ol9.tar.gz $(eval $(call check_packages_deps)) -ol9.tar.gz: check-deps clean http/ol9.ks +ol9.tar.gz: check-deps clean ${PACKER} init ol9.pkr.hcl && ${PACKER} build ol9.pkr.hcl -http/ol9.ks: http/ol9.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-ol9 ol9.tar.gz http/ol9.ks - -.INTERMEDIATE: http/ol9.ks + ${RM} -rf output-ol9 ol9.tar.gz diff --git a/ol9/README.md b/ol9/README.md index 995c4bef..52a07f9f 100644 --- a/ol9/README.md +++ b/ol9/README.md @@ -30,7 +30,7 @@ To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image @@ -46,7 +46,6 @@ be in packer-maas/ol9, where this file is located. Once in packer-maas/ol9 you can generate an image with: ```shell -envsubst '$${KS_PROXY}' < http/ol9.ks.in | tee http/ol9.ks packer init . PACKER_LOG=1 packer build . ``` diff --git a/ol9/http/ol9.ks.in b/ol9/http/ol9.ks.pkrtpl.hcl similarity index 89% rename from ol9/http/ol9.ks.in rename to ol9/http/ol9.ks.pkrtpl.hcl index 1c7b3adb..e6d10007 100644 --- a/ol9/http/ol9.ks.in +++ b/ol9/http/ol9.ks.pkrtpl.hcl @@ -1,4 +1,4 @@ -url --url="https://yum.oracle.com/repo/OracleLinux/OL9/baseos/latest/x86_64" ${KS_PROXY} +url ${KS_OS_REPOS} ${KS_PROXY} poweroff firstboot --disable ignoredisk --only-use=vda @@ -11,7 +11,7 @@ timezone UTC --utc bootloader --location=mbr --driveorder="vda" --timeout=1 rootpw --plaintext password -repo --name="ol9_AppStream" --baseurl="https://yum.oracle.com/repo/OracleLinux/OL9/appstream/x86_64/" ${KS_PROXY} +repo --name="ol9_AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY} zerombr clearpart --all --initlabel diff --git a/ol9/ol9.pkr.hcl b/ol9/ol9.pkr.hcl index 9e0d1717..e8cfb639 100644 --- a/ol9/ol9.pkr.hcl +++ b/ol9/ol9.pkr.hcl @@ -24,18 +24,55 @@ variable "ol9_sha256sum_path" { default = "https://linux.oracle.com/security/gpg/checksum/OracleLinux-R9-U2-Server-x86_64.checksum" } +# use can use "--url" to specify the exact url for os repo +variable "ks_os_repos" { + type = string + default = "--url='https://yum.oracle.com/repo/OracleLinux/OL9/baseos/latest/x86_64'" +} + +# Use --baseurl to specify the exact url for AppStream repo +variable "ks_appstream_repos" { + type = string + default = "--baseurl='https://yum.oracle.com/repo/OracleLinux/OL9/appstream/x86_64/'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +variable ks_mirror { + type = string + default = "${env("KS_MIRROR")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" + ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/baseos/latest/x86_64" : var.ks_os_repos + ks_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/appstream/x86_64/" : var.ks_appstream_repos +} + source "qemu" "ol9" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ol9.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "file:${var.ol9_sha256sum_path}" iso_url = var.ol9_iso_url memory = 2048 qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] shutdown_timeout = "1h" + http_content = { + "/ol9.ks" = templatefile("${path.root}/http/ol9.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_OS_REPOS = local.ks_os_repos, + KS_APPSTREAM_REPOS = local.ks_appstream_repos, + } + ) + } + } build { @@ -43,10 +80,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=ol9", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/rhel7/Makefile b/rhel7/Makefile index 1a53fff8..1ec7f3f4 100644 --- a/rhel7/Makefile +++ b/rhel7/Makefile @@ -6,7 +6,7 @@ PACKER ?= packer PACKER_LOG ?= 0 ISO ?= ${RHEL7_ISO_PATH} -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -14,13 +14,8 @@ all: rhel7.tar.gz $(eval $(call check_packages_deps)) -rhel7.tar.gz: check-deps clean http/rhel7.ks +rhel7.tar.gz: check-deps clean ${PACKER} init rhel7.pkr.hcl && ${PACKER} build -var "rhel7_iso_path=${ISO}" rhel7.pkr.hcl -http/rhel7.ks: http/rhel7.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-rhel7 rhel7.tar.gz http/rhel7.ks - -.INTERMEDIATE: http/rhel7.ks + ${RM} -rf output-rhel7 rhel7.tar.gz diff --git a/rhel7/README.md b/rhel7/README.md index 1f40eaad..a32f3913 100644 --- a/rhel7/README.md +++ b/rhel7/README.md @@ -27,7 +27,7 @@ cloud-init repository. To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image diff --git a/rhel7/http/rhel7.ks.in b/rhel7/http/rhel7.ks.pkrtpl.hcl similarity index 91% rename from rhel7/http/rhel7.ks.in rename to rhel7/http/rhel7.ks.pkrtpl.hcl index f0114967..9fa6f372 100644 --- a/rhel7/http/rhel7.ks.in +++ b/rhel7/http/rhel7.ks.pkrtpl.hcl @@ -12,8 +12,8 @@ timezone UTC --isUtc bootloader --location=mbr --driveorder="vda" --timeout=1 rootpw --plaintext password -repo --name="Server-HighAvailability" --baseurl="file:///run/install/repo/addons/HighAvailability" -repo --name="Server-ResilientStorage" --baseurl="file:///run/install/repo/addons/ResilientStorage" +repo --name="Server-HighAvailability" ${KS_HA_REPOS} ${KS_PROXY} +repo --name="Server-ResilientStorage" ${KS_STORAGE_REPOS} ${KS_PROXY} zerombr clearpart --all --initlabel diff --git a/rhel7/rhel7.pkr.hcl b/rhel7/rhel7.pkr.hcl index 6410ea3f..91700f49 100644 --- a/rhel7/rhel7.pkr.hcl +++ b/rhel7/rhel7.pkr.hcl @@ -19,18 +19,48 @@ variable "rhel7_iso_path" { default = "${env("RHEL7_ISO_PATH")}" } +# Use --baseurl to specify the exact url for HighAvailability repo +variable "ks_ha_repos" { + type = string + default = "--baseurl='file:///run/install/repo/addons/HighAvailability'" +} + +# Use --baseurl to specify the exact url for ResilientStorage repo +variable "ks_storage_repos" { + type = string + default = "--baseurl='file:///run/install/repo/addons/ResilientStorage'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" +} + source "qemu" "rhel7" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel7.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "none" iso_url = var.rhel7_iso_path memory = 2048 qemuargs = [["-serial", "stdio"]] shutdown_timeout = "1h" + http_content = { + "/rhel7.ks" = templatefile("${path.root}/http/rhel7.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_HA_REPOS = var.ks_ha_repos, + KS_STORAGE_REPOS = var.ks_storage_repos, + } + ) + } + } build { @@ -38,10 +68,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=rhel7", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/rhel8/Makefile b/rhel8/Makefile index 4660c356..2418c93c 100644 --- a/rhel8/Makefile +++ b/rhel8/Makefile @@ -6,7 +6,7 @@ PACKER ?= packer PACKER_LOG ?= 0 ISO ?= ${RHEL8_ISO_PATH} -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -14,13 +14,8 @@ all: rhel8.tar.gz $(eval $(call check_packages_deps)) -rhel8.tar.gz: check-deps clean http/rhel8.ks +rhel8.tar.gz: check-deps clean ${PACKER} init rhel8.pkr.hcl && ${PACKER} build -var "rhel8_iso_path=${ISO}" rhel8.pkr.hcl -http/rhel8.ks: http/rhel8.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-rhel8 rhel8.tar.gz http/rhel8.ks - -.INTERMEDIATE: http/rhel8.ks \ No newline at end of file + ${RM} -rf output-rhel8 rhel8.tar.gz diff --git a/rhel8/README.md b/rhel8/README.md index fe1457ba..ac6ef16d 100644 --- a/rhel8/README.md +++ b/rhel8/README.md @@ -27,7 +27,7 @@ cloud-init repository. To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image diff --git a/rhel9/http/rhel9.ks.in b/rhel8/http/rhel8.ks.pkrtpl.hcl similarity index 96% rename from rhel9/http/rhel9.ks.in rename to rhel8/http/rhel8.ks.pkrtpl.hcl index caa543df..a07d7652 100644 --- a/rhel9/http/rhel9.ks.in +++ b/rhel8/http/rhel8.ks.pkrtpl.hcl @@ -12,7 +12,7 @@ timezone UTC --isUtc bootloader --location=mbr --driveorder="vda" --timeout=1 rootpw --plaintext password -repo --name="AppStream" --baseurl="file:///run/install/repo/AppStream" +repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY} zerombr clearpart --all --initlabel diff --git a/rhel8/rhel8.pkr.hcl b/rhel8/rhel8.pkr.hcl index ca90a7c1..2349a510 100644 --- a/rhel8/rhel8.pkr.hcl +++ b/rhel8/rhel8.pkr.hcl @@ -19,18 +19,41 @@ variable "rhel8_iso_path" { default = "${env("RHEL8_ISO_PATH")}" } +# Use --baseurl to specify the exact url for AppStream repo +variable "ks_appstream_repos" { + type = string + default = "--baseurl='file:///run/install/repo/AppStream'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" +} + source "qemu" "rhel8" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel8.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "none" iso_url = var.rhel8_iso_path memory = 2048 qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] shutdown_timeout = "1h" + http_content = { + "/rhel8.ks" = templatefile("${path.root}/http/rhel8.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_APPSTREAM_REPOS = var.ks_appstream_repos, + } + ) + } + } build { @@ -38,10 +61,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=rhel8", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/rhel9/Makefile b/rhel9/Makefile index a30bdc09..db0a6b2f 100644 --- a/rhel9/Makefile +++ b/rhel9/Makefile @@ -6,7 +6,7 @@ PACKER ?= packer PACKER_LOG ?= 0 ISO ?= rhel-baseos-9.1-x86_64-dvd.iso -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -14,13 +14,8 @@ all: rhel9.tar.gz $(eval $(call check_packages_deps)) -rhel9.tar.gz: check-deps clean http/rhel9.ks +rhel9.tar.gz: check-deps clean ${PACKER} init rhel9.pkr.hcl && ${PACKER} build -var "rhel9_iso_path=${ISO}" rhel9.pkr.hcl -http/rhel9.ks: http/rhel9.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-rhel9 rhel9.tar.gz http/rhel9.ks - -.INTERMEDIATE: http/rhel9.ks + ${RM} -rf output-rhel9 rhel9.tar.gz diff --git a/rhel9/README.md b/rhel9/README.md index f8b30d33..a65a357f 100644 --- a/rhel9/README.md +++ b/rhel9/README.md @@ -27,7 +27,7 @@ cloud-init repository. To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` ## Building an image diff --git a/rhel8/http/rhel8.ks.in b/rhel9/http/rhel9.ks.pkrtpl.hcl similarity index 96% rename from rhel8/http/rhel8.ks.in rename to rhel9/http/rhel9.ks.pkrtpl.hcl index caa543df..a07d7652 100644 --- a/rhel8/http/rhel8.ks.in +++ b/rhel9/http/rhel9.ks.pkrtpl.hcl @@ -12,7 +12,7 @@ timezone UTC --isUtc bootloader --location=mbr --driveorder="vda" --timeout=1 rootpw --plaintext password -repo --name="AppStream" --baseurl="file:///run/install/repo/AppStream" +repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY} zerombr clearpart --all --initlabel diff --git a/rhel9/rhel9.pkr.hcl b/rhel9/rhel9.pkr.hcl index 6f09ab4b..beeca096 100644 --- a/rhel9/rhel9.pkr.hcl +++ b/rhel9/rhel9.pkr.hcl @@ -19,18 +19,41 @@ variable "rhel9_iso_path" { default = "${env("RHEL9_ISO_PATH")}" } +# Use --baseurl to specify the exact url for AppStream repo +variable "ks_appstream_repos" { + type = string + default = "--baseurl='file:///run/install/repo/AppStream'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" +} + source "qemu" "rhel9" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel9.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = true - http_directory = "http" iso_checksum = "none" iso_url = var.rhel9_iso_path memory = 2048 qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] shutdown_timeout = "1h" + http_content = { + "/rhel9.ks" = templatefile("${path.root}/http/rhel9.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_APPSTREAM_REPOS = var.ks_appstream_repos, + } + ) + } + } build { @@ -38,10 +61,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=rhel9", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/rocky9/Makefile b/rocky9/Makefile index afd3d4d2..ab3e2151 100644 --- a/rocky9/Makefile +++ b/rocky9/Makefile @@ -5,7 +5,7 @@ include ../scripts/check.mk PACKER ?= packer PACKER_LOG ?= 0 -export PACKER_LOG KS_PROXY +export PACKER_LOG .PHONY: all clean @@ -13,13 +13,8 @@ all: rocky9.tar.gz $(eval $(call check_packages_deps)) -rocky9.tar.gz: check-deps clean http/rocky.ks +rocky9.tar.gz: check-deps clean ${PACKER} init rocky9.pkr.hcl && ${PACKER} build rocky9.pkr.hcl -http/rocky.ks: http/rocky.ks.in - envsubst '$${KS_PROXY}' < $< | tee $@ - clean: - ${RM} -rf output-rocky9 rocky9.tar.gz http/rocky.ks - -.INTERMEDIATE: http/rocky.ks + ${RM} -rf output-rocky9 rocky9.tar.gz diff --git a/rocky9/README.md b/rocky9/README.md index 15e3612a..c444dce5 100644 --- a/rocky9/README.md +++ b/rocky9/README.md @@ -26,7 +26,7 @@ The Packer template downloads the Rocky ISO image from the Internet. You can tel To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: ```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" +export KS_PROXY=$HTTP_PROXY ``` diff --git a/rocky9/http/rocky.ks.in b/rocky9/http/rocky.ks.pkrtpl.hcl similarity index 85% rename from rocky9/http/rocky.ks.in rename to rocky9/http/rocky.ks.pkrtpl.hcl index 68fef48b..e02eeb53 100644 --- a/rocky9/http/rocky.ks.in +++ b/rocky9/http/rocky.ks.pkrtpl.hcl @@ -1,7 +1,7 @@ -url --url="https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/" ${KS_PROXY} -url --mirrorlist="http://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-9" ${KS_PROXY} -repo --name="AppStream" --mirrorlist="https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&release=9&repo=AppStream-9" ${KS_PROXY} -repo --name="Extras" --mirrorlist="https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=extras-9" ${KS_PROXY} +url ${KS_OS_REPOS} ${KS_PROXY} +url ${KS_BASE_OS_REPOS} ${KS_PROXY} +repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY} +repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY} eula --agreed diff --git a/rocky9/rocky9.pkr.hcl b/rocky9/rocky9.pkr.hcl index 62cec616..4b4e5414 100644 --- a/rocky9/rocky9.pkr.hcl +++ b/rocky9/rocky9.pkr.hcl @@ -30,18 +30,70 @@ variable "rocky_sha256sum_url" { default = "https://download.rockylinux.org/pub/rocky/9/isos/x86_64/CHECKSUM" } +# use can use "--url" to specify the exact url for os repo +variable "ks_os_repos" { + type = string + default = "--url='https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/'" +} + +# Use --baseurl to specify the exact url for base_os repo +variable "ks_base_os_repos" { + type = string + default = "--mirrorlist='http://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-9'" +} + +# Use --baseurl to specify the exact url for appstream repo +variable "ks_appstream_repos" { + type = string + default = "--mirrorlist='https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&release=9&repo=AppStream-9'" +} + +# Use --baseurl to specify the exact url for extras repo +variable "ks_extras_repos" { + type = string + default = "--mirrorlist='https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=extras-9'" +} + +variable ks_proxy { + type = string + default = "${env("KS_PROXY")}" +} + +variable ks_mirror { + type = string + default = "${env("KS_MIRROR")}" +} + +locals { + ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : "" + ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/BaseOS/x86_64/os" : var.ks_os_repos + ks_base_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/BaseOS/x86_64/os" : var.ks_base_os_repos + ks_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/AppStream/x86_64/os" : var.ks_appstream_repos + ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/x86_64/os" : var.ks_extras_repos +} + source "qemu" "rocky9" { boot_command = [" ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rocky.ks ", "console=ttyS0 inst.cmdline", ""] boot_wait = "3s" communicator = "none" disk_size = "4G" headless = var.headless - http_directory = "http" iso_checksum = "file:${var.rocky_sha256sum_url}" iso_url = "${var.rocky_iso_url}" memory = 2048 qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] shutdown_timeout = "1h" + http_content = { + "/rocky.ks" = templatefile("${path.root}/http/rocky.ks.pkrtpl.hcl", + { + KS_PROXY = local.ks_proxy, + KS_OS_REPOS = local.ks_os_repos, + KS_BASE_OS_REPOS = local.ks_base_os_repos, + KS_APPSTREAM_REPOS = local.ks_appstream_repos, + KS_EXTRAS_REPOS = local.ks_extras_repos + } + ) + } } build { @@ -49,10 +101,11 @@ build { post-processor "shell-local" { inline = [ - "SOURCE=rocky9", + "SOURCE=${source.name}", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", - "source ../scripts/fuse-tar-root" + "source ../scripts/fuse-tar-root", + "rm -rf output-${source.name}", ] inline_shebang = "/bin/bash -e" } diff --git a/sles12/README.md b/sles12/README.md index 5fdde2a3..0285ea3c 100644 --- a/sles12/README.md +++ b/sles12/README.md @@ -21,14 +21,6 @@ The Packer template in this directory creates a SLES 12 AMD64 image for use with The deployment image may be customized using `cloud-init` configuration. Check the `user-data` file. -## Building the image using a proxy - -The Packer template pulls all packages from the upstream image. To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow: - -```shell -export KS_PROXY="--proxy=\"${HTTP_PROXY}\"" -``` - ## Building an image You can easily build the image using the Makefile: