Skip to content

Commit

Permalink
add rocky9 to test
Browse files Browse the repository at this point in the history
  • Loading branch information
goffinet committed Oct 20, 2024
1 parent a2c1a1b commit 95bfa76
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 1 deletion.
6 changes: 6 additions & 0 deletions build-packer-templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
iso_url: "https://repo.almalinux.org/almalinux/9.4/isos/x86_64"
iso_name: "AlmaLinux-9.4-x86_64-boot.iso"
checksum_filename: "CHECKSUM"
- type: "redhat"
flavor: "rocky"
version: "9.4"
iso_url: "https://download.rockylinux.org/pub/rocky/9.4/isos/x86_64/"
iso_name: "Rocky-9.4-x86_64-boot.iso "
checksum_filename: "CHECKSUM"
- type: "redhat"
flavor: "centos"
version: "9"
Expand Down
76 changes: 76 additions & 0 deletions http/rocky9-kickstart.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#Generated by packer-kvm/build-packer-templates.yaml

#auth --enableshadow --passalgo=sha512
url --url="https://download.rockylinux.org/pub/rocky/9.4/BaseOS/x86_64//kickstart/"
text
firstboot --disable
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network --hostname=rocky9.localdomain
selinux --disabled
rootpw testtest
user --groups=wheel --name=user --password=testtest --uid=1000 --gecos="user" --gid=1000
sshkey --username=user "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDUXg2vJmOBNIHd5j6gWFBs0/I4IWXp1jIHBn93FyUQsgiVOG82jhCA69G2SqCYbZHRJSJhwOFSMtMsvDno5Gz+tZMSASliiQnDD26YxiqZZUOApqCpdYKYEhwjVcokjKfm1rVdYhysk1K/qmlL6D0SVAzZxsepl7x8JksMVjvOsuGsZywsvh/Ck7JqEMt9O/NDWv0iFGkGy7J888eAnc+bMyiVV4ND+yYPqpCtL+fPU/dY7+LMR9uDoiJK8fAOmCrBvRLwmKOCh4NNRsHk58L36gl3ArUpNlqWrotpLROHhrXcuh4hSmPuTVsxQOTrzaHM2oVkw/+LBpFFqMLJrAaM8sVrfUBAhRD91cFHjazXg7RvXE1dbkPWDH6THJ71CS1FLyz2htMd7nYuJX/3J2bk533JKZVy/nOEtb0k2s1yCw4WNhT7M+RSFjsvgFsJJkvcGKPpIUwdkctzAXj4hAC1sdhiLsdh/j9E5yw2Tr6rRZ4nuBGDUOqlHABSZBm1d6k= packer-kvm-default-key"
sshkey --username=root "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDUXg2vJmOBNIHd5j6gWFBs0/I4IWXp1jIHBn93FyUQsgiVOG82jhCA69G2SqCYbZHRJSJhwOFSMtMsvDno5Gz+tZMSASliiQnDD26YxiqZZUOApqCpdYKYEhwjVcokjKfm1rVdYhysk1K/qmlL6D0SVAzZxsepl7x8JksMVjvOsuGsZywsvh/Ck7JqEMt9O/NDWv0iFGkGy7J888eAnc+bMyiVV4ND+yYPqpCtL+fPU/dY7+LMR9uDoiJK8fAOmCrBvRLwmKOCh4NNRsHk58L36gl3ArUpNlqWrotpLROHhrXcuh4hSmPuTVsxQOTrzaHM2oVkw/+LBpFFqMLJrAaM8sVrfUBAhRD91cFHjazXg7RvXE1dbkPWDH6THJ71CS1FLyz2htMd7nYuJX/3J2bk533JKZVy/nOEtb0k2s1yCw4WNhT7M+RSFjsvgFsJJkvcGKPpIUwdkctzAXj4hAC1sdhiLsdh/j9E5yw2Tr6rRZ4nuBGDUOqlHABSZBm1d6k= packer-kvm-default-key"
timezone Europe/Paris --utc
bootloader --location=mbr --append=" net.ifnames=0 biosdevname=0 crashkernel=no"
# Clear the Master Boot Record
zerombr
# Remove partitions
clearpart --all --initlabel
# Automatically create partitions using LVM
autopart --type=lvm
# Reboot after successful installation
reboot

%packages --excludedocs
sudo
qemu-guest-agent
openssh-server
-kexec-tools
-dracut-config-rescue
-plymouth*
-iwl*firmware
%end

%addon com_redhat_kdump --disable
%end

%post
# Update time
#/usr/sbin/ntpdate -bu 0.fr.pool.ntp.org 1.fr.pool.ntp.org

#sed -i 's/^.*requiretty/#Defaults requiretty/' /etc/sudoers
sed -i 's/rhgb //' /etc/default/grub

# Disable consistent network device naming
#/usr/bin/ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules

# sshd PermitRootLogin yes
sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
#echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
cat <<EOF >> /etc/sudoers
Defaults !requiretty
root ALL=(ALL) ALL
user ALL=(ALL) NOPASSWD: ALL
EOF

# Enable NetworkManager, sshd and disable firewalld
#/usr/bin/systemctl enable NetworkManager
/usr/bin/systemctl enable sshd
/usr/bin/systemctl start sshd
#/usr/bin/systemctl disable firewalld

# Need for host/guest communication
/usr/bin/systemctl enable qemu-guest-agent
/usr/bin/systemctl start qemu-guest-agent

# Update all packages
#/usr/bin/dnf -y update
#/usr/bin/dnf clean all

# Not really needed since the kernel update already did this. Furthermore,
# running this here reverts the grub menu to the current kernel.
grub2-mkconfig -o /boot/grub2/grub.cfg
%end
117 changes: 117 additions & 0 deletions rocky9.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#Generated by packer-kvm/build-packer-templates.yaml

packer {
required_plugins {
qemu = {
version = "~> 1"
source = "github.com/hashicorp/qemu"
}
ansible = {
version = ">= 1.1.2"
source = "github.com/hashicorp/ansible"
}
}
}

variable "config_file" {
type = string
default = "rocky9-kickstart.cfg"
}

variable "cpu" {
type = string
default = "2"
}

variable "destination_server" {
type = string
default = "download.goffinet.org"
}

variable "disk_size" {
type = string
default = "40000"
}

variable "headless" {
type = string
default = "true"
}

variable "iso_checksum" {
type = string
default = "file:https://download.rockylinux.org/pub/rocky/9.4/isos/x86_64//CHECKSUM"
}

variable "iso_url" {
type = string
default = "https://download.rockylinux.org/pub/rocky/9.4/isos/x86_64//Rocky-9.4-x86_64-boot.iso "
}

variable "name" {
type = string
default = "rocky"
}

variable "ram" {
type = string
default = "2048"
}

variable "ssh_password" {
type = string
default = "testtest"
}

variable "ssh_username" {
type = string
default = "root"
}

variable "version" {
type = string
default = "9"
}

source "qemu" "rocky9" {
accelerator = "kvm"
boot_command = ["<tab><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs> inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/http/${var.config_file}<enter><wait>"]
disk_cache = "none"
disk_compression = true
disk_discard = "unmap"
disk_interface = "virtio"
disk_size = var.disk_size
format = "qcow2"
headless = var.headless
http_directory = "."
iso_checksum = var.iso_checksum
iso_url = var.iso_url
net_device = "virtio-net"
output_directory = "artifacts/qemu/${var.name}${var.version}"
qemu_binary = "/usr/bin/qemu-system-x86_64"
qemuargs = [["-m", "${var.ram}M"], ["-smp", "${var.cpu}"], ["-cpu", "host"]]
shutdown_command = "sudo /usr/sbin/shutdown -h now"
ssh_password = var.ssh_password
ssh_username = var.ssh_username
ssh_wait_timeout = "30m"
boot_wait = "10s"
}

build {
sources = ["source.qemu.rocky9"]

provisioner "shell" {
execute_command = "{{ .Vars }} sudo -E bash '{{ .Path }}'"
inline = ["dnf -y install python3 python3-pip", "pip3 install ansible"]
}

provisioner "ansible-local" {
playbook_dir = "ansible"
playbook_file = "ansible/playbook.yml"
}

post-processor "shell-local" {
environment_vars = ["IMAGE_NAME=${var.name}", "IMAGE_VERSION=${var.version}", "DESTINATION_SERVER=${var.destination_server}"]
script = "scripts/push-image.sh"
}
}
2 changes: 1 addition & 1 deletion roles/build_packer_templates/templates/kickstart.cfg.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Generated by packer-kvm/build-packer-templates.yaml

#auth --enableshadow --passalgo=sha512
url --url="{% if item.flavor == 'almalinux' %}{{ item.iso_url | regex_replace('isos', 'BaseOS') }}/kickstart/{% elif item.flavor == 'centos' or item.flavor == 'fedora' %}{{ item.iso_url | regex_replace('iso', 'os') }}{% endif %}"
url --url="{% if item.flavor == 'almalinux' or item.flavor == 'rocky' %}{{ item.iso_url | regex_replace('isos', 'BaseOS') }}/kickstart/{% elif item.flavor == 'centos' or item.flavor == 'fedora' %}{{ item.iso_url | regex_replace('iso', 'os') }}{% endif %}"
text
firstboot --disable
keyboard --vckeymap=us --xlayouts='us'
Expand Down

0 comments on commit 95bfa76

Please sign in to comment.