From dcbc398e81071df892d81333f7eac17934bb0795 Mon Sep 17 00:00:00 2001 From: tigro Date: Sun, 24 Mar 2024 22:14:09 +0300 Subject: [PATCH] Added MSVSphere 8 support --- http/msvsphere-8-gencloud.x86_64.ks | 53 ++++++++++++++++++ http/msvsphere-8-vagrant.x86_64.ks | 57 +++++++++++++++++++ msvsphere-8-gencloud.pkr.hcl | 54 ++++++++++++++++++ msvsphere-8-vagrant.pkr.hcl | 85 +++++++++++++++++++++++++++++ msvsphere-8-yandexcloud.pkr.hcl | 54 ++++++++++++++++++ variables.pkr.hcl | 45 +++++++++++++++ 6 files changed, 348 insertions(+) create mode 100644 http/msvsphere-8-gencloud.x86_64.ks create mode 100644 http/msvsphere-8-vagrant.x86_64.ks create mode 100644 msvsphere-8-gencloud.pkr.hcl create mode 100644 msvsphere-8-vagrant.pkr.hcl create mode 100644 msvsphere-8-yandexcloud.pkr.hcl diff --git a/http/msvsphere-8-gencloud.x86_64.ks b/http/msvsphere-8-gencloud.x86_64.ks new file mode 100644 index 0000000..dda53e4 --- /dev/null +++ b/http/msvsphere-8-gencloud.x86_64.ks @@ -0,0 +1,53 @@ +# AlmaLinux 8 kickstart file for Generic Cloud (OpenStack) image + +url --url https://rsync.inferitos.ru/msvsphere/8/BaseOS/x86_64/kickstart/ +repo --name=BaseOS --baseurl=https://rsync.inferitos.ru/msvsphere/8/BaseOS/x86_64/os/ +repo --name=AppStream --baseurl=https://rsync.inferitos.ru/msvsphere/8/AppStream/x86_64/os/ + +text +skipx +eula --agreed +firstboot --disabled + +lang en_US.UTF-8 +keyboard us +timezone UTC --isUtc + +network --bootproto=dhcp +firewall --enabled --service=ssh +services --disabled="kdump" --enabled="chronyd,rsyslog,sshd" +selinux --enforcing + +# TODO: remove "console=tty0" from here +bootloader --append="console=ttyS0,115200n8 console=tty0 crashkernel=auto net.ifnames=0 no_timer_check" --location=mbr --timeout=1 +zerombr +clearpart --all --initlabel +reqpart +part / --fstype="xfs" --size=8000 + +rootpw --plaintext msvsphere + +reboot --eject + +%packages +@core +-biosdevname +-open-vm-tools +-plymouth +-dnf-plugin-spacewalk +-rhn* +-iprutils +-iwl*-firmware +sphere-release-identity-server +sphere-release-server +sphere-release +%end + + +# disable kdump service +%addon com_redhat_kdump --disable +%end + + +%post +%end diff --git a/http/msvsphere-8-vagrant.x86_64.ks b/http/msvsphere-8-vagrant.x86_64.ks new file mode 100644 index 0000000..a011e47 --- /dev/null +++ b/http/msvsphere-8-vagrant.x86_64.ks @@ -0,0 +1,57 @@ +# MSVSphere 8 Vagrant boxes kickstart file + +# TODO: change url to the kickstart one when we have it +url --url https://rsync.inferitos.ru/msvsphere/8/BaseOS/x86_64/kickstart/ +repo --name=BaseOS --baseurl=https://rsync.inferitos.ru/msvsphere/8/BaseOS/x86_64/os/ +repo --name=AppStream --baseurl=https://rsync.inferitos.ru/msvsphere/8/AppStream/x86_64/os/ + +text +skipx +eula --agreed +firstboot --disabled + +lang en_US.UTF-8 +keyboard us +timezone UTC --isUtc + +network --bootproto=dhcp +firewall --disabled +services --enabled=sshd +selinux --enforcing + +bootloader --location=mbr +zerombr +clearpart --all --initlabel +autopart --type=plain --nohome --noboot --noswap + +rootpw vagrant +user --name=vagrant --plaintext --password vagrant + +reboot --eject + + +%packages --ignoremissing --excludedocs --instLangs=en_US.UTF-8 +bzip2 +tar +-microcode_ctl +-iwl*-firmware +sphere-release-identity-server +sphere-release-server +sphere-release +%end + + +# disable kdump service +%addon com_redhat_kdump --disable +%end + + +%post +# allow passwordless sudo for the vagrant user +echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant + +# see Vagrant documentation (https://docs.vagrantup.com/v2/boxes/base.html) +# for details about the requiretty. +sed -i "s/^.*requiretty/# Defaults requiretty/" /etc/sudoers +yum clean all +%end diff --git a/msvsphere-8-gencloud.pkr.hcl b/msvsphere-8-gencloud.pkr.hcl new file mode 100644 index 0000000..4f958eb --- /dev/null +++ b/msvsphere-8-gencloud.pkr.hcl @@ -0,0 +1,54 @@ +/* + * MSVSphere OS 8 Packer template for building Generic Cloud (OpenStack compatible) images. + */ + +source "qemu" "msvsphere-8-gencloud-x86_64" { + iso_url = var.iso_url_8_x86_64 + iso_checksum = var.iso_checksum_8_x86_64 + shutdown_command = var.root_shutdown_command + accelerator = "kvm" + http_directory = var.http_directory + ssh_username = var.gencloud_ssh_username + ssh_password = var.gencloud_ssh_password + ssh_timeout = var.ssh_timeout + vnc_bind_address = var.vnc_bind_address + vnc_port_min = var.vnc_port_min + vnc_port_max = var.vnc_port_max + cpus = var.cpus + efi_firmware_code = var.uefi_ovmf_code + efi_firmware_vars = var.uefi_ovmf_vars + disk_interface = "virtio-scsi" + disk_size = var.gencloud_disk_size + disk_cache = "unsafe" + disk_discard = "unmap" + disk_detect_zeroes = "unmap" + disk_compression = true + format = "qcow2" + headless = var.headless + machine_type = "q35" + memory = var.memory + net_device = "virtio-net" + qemu_binary = var.qemu_binary + vm_name = "MSVSphere-${var.os_version_8}-${formatdate("YYYYMMDD", timestamp())}.gencloud.x86_64.qcow2" + boot_wait = var.boot_wait + boot_command = var.gencloud_boot_cmd_8_x86_64_uefi +} + +build { + sources = [ + "qemu.msvsphere-8-gencloud-x86_64" + ] + + provisioner "ansible" { + playbook_file = "ansible/gencloud.yml" + galaxy_file = "ansible/requirements.yml" + roles_path = "ansible/roles" + collections_path = "ansible/collections" + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True", + "ANSIBLE_REMOTE_TEMP=/tmp", + "ANSIBLE_SSH_ARGS='-o ControlMaster=no -o ControlPersist=180s -o ServerAliveInterval=120s -o TCPKeepAlive=yes -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa'" + ] + extra_arguments = ["--scp-extra-args", "'-O'"] + } +} diff --git a/msvsphere-8-vagrant.pkr.hcl b/msvsphere-8-vagrant.pkr.hcl new file mode 100644 index 0000000..eb3e012 --- /dev/null +++ b/msvsphere-8-vagrant.pkr.hcl @@ -0,0 +1,85 @@ +/** + * Packer template for building MSVSphere 8 Vagrant boxes. + */ + +source "virtualbox-iso" "msvsphere-8-vagrant-x86_64" { + iso_url = var.iso_url_8_x86_64 + iso_checksum = var.iso_checksum_8_x86_64 + boot_command = var.vagrant_boot_cmd_8_x86_64_bios + boot_wait = var.boot_wait + cpus = var.cpus + memory = var.memory + disk_size = var.vagrant_disk_size + headless = var.headless + http_directory = var.http_directory + guest_os_type = "RedHat_64" + shutdown_command = var.vagrant_shutdown_command + ssh_username = var.vagrant_ssh_username + ssh_password = var.vagrant_ssh_password + ssh_timeout = var.ssh_timeout + hard_drive_interface = "sata" + iso_interface = "sata" + vboxmanage = [ + ["modifyvm", "{{.Name}}", "--nat-localhostreachable1", "on"], + ] + vboxmanage_post = [ + ["modifyvm", "{{.Name}}", "--memory", var.post_memory], + ["modifyvm", "{{.Name}}", "--cpus", var.post_cpus] + ] +} + +source "vmware-iso" "msvsphere-8-vagrant-x86_64" { + iso_url = var.iso_url_8_x86_64 + iso_checksum = var.iso_checksum_8_x86_64 + boot_command = var.vagrant_boot_cmd_8_x86_64_bios + boot_wait = var.boot_wait + cpus = var.cpus + memory = var.memory + disk_size = var.vagrant_disk_size + headless = var.headless + http_directory = var.http_directory + guest_os_type = "centos-64" + shutdown_command = var.vagrant_shutdown_command + ssh_username = var.vagrant_ssh_username + ssh_password = var.vagrant_ssh_password + ssh_timeout = var.ssh_timeout + vmx_data = { + "cpuid.coresPerSocket" : "1" + } + vmx_data_post = { + "memsize" : var.post_memory + "numvcpus" : var.post_cpus + } + vmx_remove_ethernet_interfaces = true +} + + +build { + sources = [ + "sources.virtualbox-iso.msvsphere-8-vagrant-x86_64", + "sources.vmware-iso.msvsphere-8-vagrant-x86_64" + ] + + provisioner "ansible" { + playbook_file = "ansible/vagrant.yml" + galaxy_file = "ansible/requirements.yml" + roles_path = "ansible/roles" + collections_path = "ansible/collections" + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True", + "ANSIBLE_REMOTE_TEMP=/tmp", + "ANSIBLE_SSH_ARGS='-o ControlMaster=no -o ControlPersist=180s -o ServerAliveInterval=120s -o TCPKeepAlive=yes -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa'" + ] + extra_arguments = [ + "--extra-vars", + "packer_provider=${source.type}" + ] + } + + post-processors { + post-processor "vagrant" { + compression_level = "8" + output = "MSVSphere-${var.os_version_8}-${formatdate("YYYYMMDD", timestamp())}.{{.Provider}}.x86_64.box" + } + } +} diff --git a/msvsphere-8-yandexcloud.pkr.hcl b/msvsphere-8-yandexcloud.pkr.hcl new file mode 100644 index 0000000..62c3376 --- /dev/null +++ b/msvsphere-8-yandexcloud.pkr.hcl @@ -0,0 +1,54 @@ +/* + * MSVSphere OS 8 Packer template for building Generic Cloud (OpenStack compatible) images. + */ + +source "qemu" "msvsphere-8-yandexcloud-x86_64" { + iso_url = var.iso_url_8_x86_64 + iso_checksum = var.iso_checksum_8_x86_64 + shutdown_command = var.root_shutdown_command + accelerator = "kvm" + http_directory = var.http_directory + ssh_username = var.gencloud_ssh_username + ssh_password = var.gencloud_ssh_password + ssh_timeout = var.ssh_timeout + vnc_bind_address = var.vnc_bind_address + vnc_port_min = var.vnc_port_min + vnc_port_max = var.vnc_port_max + cpus = var.cpus + efi_firmware_code = var.uefi_ovmf_code + efi_firmware_vars = var.uefi_ovmf_vars + disk_interface = "virtio-scsi" + disk_size = var.gencloud_disk_size + disk_cache = "unsafe" + disk_discard = "unmap" + disk_detect_zeroes = "unmap" + disk_compression = true + format = "qcow2" + headless = var.headless + machine_type = "q35" + memory = var.memory + net_device = "virtio-net" + qemu_binary = var.qemu_binary + vm_name = "MSVSphere-${var.os_version_8}-${formatdate("YYYYMMDD", timestamp())}.yandexcloud.x86_64.qcow2" + boot_wait = var.boot_wait + boot_command = var.gencloud_boot_cmd_8_x86_64_uefi +} + +build { + sources = [ + "qemu.msvsphere-8-yandexcloud-x86_64" + ] + + provisioner "ansible" { + playbook_file = "ansible/yandexcloud.yml" + galaxy_file = "ansible/requirements.yml" + roles_path = "ansible/roles" + collections_path = "ansible/collections" + ansible_env_vars = [ + "ANSIBLE_PIPELINING=True", + "ANSIBLE_REMOTE_TEMP=/tmp", + "ANSIBLE_SSH_ARGS='-o ControlMaster=no -o ControlPersist=180s -o ServerAliveInterval=120s -o TCPKeepAlive=yes -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa'" + ] + extra_arguments = ["--scp-extra-args", "'-O'"] + } +} diff --git a/variables.pkr.hcl b/variables.pkr.hcl index 9f9f435..f25d568 100644 --- a/variables.pkr.hcl +++ b/variables.pkr.hcl @@ -8,6 +8,12 @@ variable "os_version_9" { default = "9.3" } +variable "os_version_8" { + description = "The target MSVSphere 8 version" + type = string + default = "8.9" +} + // TODO: switch to the boot ISO on production variable "iso_url_9_x86_64" { description = "MSVSphere 9 x86_64 installation ISO URL" @@ -15,12 +21,24 @@ variable "iso_url_9_x86_64" { default = "https://repo1.msvsphere-os.ru/msvsphere/9/isos/x86_64/MSVSphere-9.3-x86_64-netinstall.iso" } +variable "iso_url_8_x86_64" { + description = "MSVSphere 8 x86_64 installation ISO URL" + type = string + default = "https://rsync.inferitos.ru/msvsphere/8/isos/x86_64/MSVSphere-8.9-x86_64-netinstall.iso" +} + variable "iso_checksum_9_x86_64" { description = "MSVSphere 9 x86_64 installation ISO checksum" type = string default = "file:https://repo1.msvsphere-os.ru/msvsphere/9/isos/x86_64/MSVSphere-9.3-x86_64-netinstall.iso.CHECKSUM" } +variable "iso_checksum_8_x86_64" { + description = "MSVSphere 8 x86_64 installation ISO checksum" + type = string + default = "file:https://rsync.inferitos.ru/msvsphere/8/isos/x86_64/MSVSphere-8.9-x86_64-netinstall.iso.CHECKSUM" +} + variable "headless" { description = "Start the VM without a GUI console if true" type = bool @@ -115,6 +133,16 @@ variable "vagrant_boot_cmd_9_x86_64_bios" { ] } +variable "vagrant_boot_cmd_8_x86_64_bios" { + description = "The boot command for x86_64 VMs in a BIOS mode" + type = list(string) + default = [ + " inst.text inst.gpt ", + "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/msvsphere-8-vagrant.x86_64.ks", + "" + ] +} + variable "vagrant_ssh_username" { description = "A login to use for SSH authentication" type = string @@ -177,6 +205,23 @@ variable "gencloud_boot_cmd_9_x86_64_uefi" { ] } +variable "gencloud_boot_cmd_8_x86_64_uefi" { + description = "The boot command for x86_64 VMs in UEFI mode" + type = list(string) + default = [ + "c", + "linuxefi", + " /images/pxeboot/vmlinuz", + " inst.stage2=hd:LABEL=MSVSphere-8-9-BaseOS-x86_64 ro", + " inst.text biosdevname=0 net.ifnames=0", + " inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/msvsphere-8-gencloud.x86_64.ks", + "", + "initrdefi /images/pxeboot/initrd.img", + "", + "boot" + ] +} + variable "gencloud_ssh_username" { description = "A login to use for SSH authentication" type = string