From 53d6b2d1d5b8eced9e3b4e5e3c48772ad217b39b Mon Sep 17 00:00:00 2001 From: AJ Schroeder <6432150+ajschroeder@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:43:03 -0600 Subject: [PATCH] initial opensuse support --- ansible/roles/base/tasks/main.yml | 15 +- ansible/roles/base/tasks/suse.yml | 9 + ansible/roles/clean/tasks/main.yml | 15 +- ansible/roles/clean/tasks/suse.yml | 80 +++ ansible/roles/configure/tasks/main.yml | 15 +- ansible/roles/configure/tasks/suse.yml | 35 + ansible/roles/users/tasks/main.yml | 13 +- .../leap-15-5/data/autoinst.pkrtpl.hcl | 625 ++++++++++++++++++ .../leap-15-5/data/storage.pkrtpl.hcl | 63 ++ .../linux-opensuse-leap.auto.pkrvars.hcl | 45 ++ .../leap-15-5/linux-opensuse-leap.pkr.hcl | 202 ++++++ .../leap-15-5/variables-storage.pkr.hcl | 53 ++ .../opensuse/leap-15-5/variables.pkr.hcl | 297 +++++++++ 13 files changed, 1450 insertions(+), 17 deletions(-) create mode 100644 ansible/roles/base/tasks/suse.yml create mode 100644 ansible/roles/clean/tasks/suse.yml create mode 100644 ansible/roles/configure/tasks/suse.yml create mode 100644 builds/linux/opensuse/leap-15-5/data/autoinst.pkrtpl.hcl create mode 100644 builds/linux/opensuse/leap-15-5/data/storage.pkrtpl.hcl create mode 100644 builds/linux/opensuse/leap-15-5/linux-opensuse-leap.auto.pkrvars.hcl create mode 100644 builds/linux/opensuse/leap-15-5/linux-opensuse-leap.pkr.hcl create mode 100644 builds/linux/opensuse/leap-15-5/variables-storage.pkr.hcl create mode 100644 builds/linux/opensuse/leap-15-5/variables.pkr.hcl diff --git a/ansible/roles/base/tasks/main.yml b/ansible/roles/base/tasks/main.yml index 1e0b717..2e51352 100644 --- a/ansible/roles/base/tasks/main.yml +++ b/ansible/roles/base/tasks/main.yml @@ -1,10 +1,19 @@ --- -- name: "Prepare the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" when: "ansible_facts['distribution'] == 'Debian'" -- name: "Prepare the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" when: "ansible_facts['distribution'] == 'Ubuntu'" -- name: "Prepare the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: redhat.yml when: "ansible_facts['distribution'] in ['RedHat', 'CentOS', 'Rocky', 'AlmaLinux', 'OracleLinux']" + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system + include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" + when: "ansible_facts['distribution'] == 'Suse'" + +... \ No newline at end of file diff --git a/ansible/roles/base/tasks/suse.yml b/ansible/roles/base/tasks/suse.yml new file mode 100644 index 0000000..82f24a2 --- /dev/null +++ b/ansible/roles/base/tasks/suse.yml @@ -0,0 +1,9 @@ +--- + +- name: Updating the operating system + ansible.builtin.zypper: + name: "*" + state: latest + update_cache: true + +... \ No newline at end of file diff --git a/ansible/roles/clean/tasks/main.yml b/ansible/roles/clean/tasks/main.yml index e9871a8..2e51352 100644 --- a/ansible/roles/clean/tasks/main.yml +++ b/ansible/roles/clean/tasks/main.yml @@ -1,10 +1,19 @@ --- -- name: "Clean the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" when: "ansible_facts['distribution'] == 'Debian'" -- name: "Clean the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" when: "ansible_facts['distribution'] == 'Ubuntu'" -- name: "Clean the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: redhat.yml when: "ansible_facts['distribution'] in ['RedHat', 'CentOS', 'Rocky', 'AlmaLinux', 'OracleLinux']" + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system + include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" + when: "ansible_facts['distribution'] == 'Suse'" + +... \ No newline at end of file diff --git a/ansible/roles/clean/tasks/suse.yml b/ansible/roles/clean/tasks/suse.yml new file mode 100644 index 0000000..a4299ba --- /dev/null +++ b/ansible/roles/clean/tasks/suse.yml @@ -0,0 +1,80 @@ +--- + +# Tasks to clean the SUSE Customer Center file. +- name: "Cleaning the SUSE Customer Center file." + file: + path: /etc/SUSEConnect + state: absent + +# Tasks to clean the audit logs. +- name: "Cleaning the audit logs." + file: + path: "{{ item }}" + state: absent + loop: + - /var/log/audit/audit.log + - /var/log/boot.log + - /var/log/lastlog + - /var/log/mail + - /var/log/messages + - /var/log/secure + - /var/log/warn + - /var/log/wtmp + - /var/log/zypper.log + +# Tasks to clean the persistent udev rules. +- name: "Cleaning persistent udev rules." + file: + path: /etc/udev/rules.d/70-persistent-net.rules + state: absent + +# Tasks to find the /tmp directories. +- name: "Finding the /tmp directories." + find: + paths: + - /tmp + - /var/tmp + - /var/cache/zypp + file_type: any + register: find_tmp_directories + +# Tasks to clean the /tmp directories. +- name: "Cleaning the /tmp directories." + file: + path: "{{ item.path }}" + state: absent + loop: "{{ find_tmp_directories.files }}" + loop_control: + label: "{{ item.path }}" + +# Tasks to find the SSH host keys. +- name: "Finding the SSH host keys." + find: + paths: /etc/ssh + patterns: 'ssh_host_*' + register: find_ssh_host_keys + +# Tasks to clean the SSH host keys. +- name: "Cleaning the SSH host keys." + file: + path: "{{ item.path }}" + state: absent + loop: "{{ find_ssh_host_keys.files }}" + loop_control: + label: "{{ item.path }}" + +# Tasks to clean the machine-id. +- name: "Emptying the /etc/machine-id." + community.general.filesize: + path: /etc/machine-id + size: 0 + +# Tasks to clean the shell history. +- name: "Cleaning the shell history." + block: + - name: "Cleaning the shell history." + file: + path: "{{ ansible_env.HOME }}/.bash_history" + state: absent + +... \ No newline at end of file diff --git a/ansible/roles/configure/tasks/main.yml b/ansible/roles/configure/tasks/main.yml index 0d850c6..2e51352 100644 --- a/ansible/roles/configure/tasks/main.yml +++ b/ansible/roles/configure/tasks/main.yml @@ -1,10 +1,19 @@ --- -- name: "Configure the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" when: "ansible_facts['distribution'] == 'Debian'" -- name: "Configure the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" when: "ansible_facts['distribution'] == 'Ubuntu'" -- name: "Configure the {{ ansible_facts['distribution'] }} guest operating system." + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system include_tasks: redhat.yml when: "ansible_facts['distribution'] in ['RedHat', 'CentOS', 'Rocky', 'AlmaLinux', 'OracleLinux']" + +- name: Prepare the {{ ansible_facts['distribution'] }} guest operating system + include_tasks: "{{ ansible_facts['distribution'] | lower }}.yml" + when: "ansible_facts['distribution'] == 'Suse'" + +... \ No newline at end of file diff --git a/ansible/roles/configure/tasks/suse.yml b/ansible/roles/configure/tasks/suse.yml new file mode 100644 index 0000000..01517ef --- /dev/null +++ b/ansible/roles/configure/tasks/suse.yml @@ -0,0 +1,35 @@ +--- + +# Tasks for unregistering from SUSE Customer Center. +- name: "Unregistering from SUSE Customer Center." + command: + cmd: "{{ item }}" + loop: + - SUSEConnect -d + - SUSEConnect --cleanup + +# Tasks for configuring SSH for public key authentication. +- name: "Configuring SSH for Public Key Authentication." + block: + - lineinfile: + path: /etc/ssh/sshd_config + regexp: '^PermitRootLogin' + line: 'PermitRootLogin no' + - lineinfile: + path: /etc/ssh/sshd_config + regexp: '^PubkeyAuthentication' + line: 'PubkeyAuthentication yes' + +# Tasks for setting the hostname. +- name: "Setting the hostname." + hostname: + name: "localhost" + +# Tasks for restarting the SSH daemon. +- name: "Restarting the SSH daemon." + systemd: + name: sshd + state: restarted + daemon_reload: true + +... \ No newline at end of file diff --git a/ansible/roles/users/tasks/main.yml b/ansible/roles/users/tasks/main.yml index 6621f98..25abe53 100644 --- a/ansible/roles/users/tasks/main.yml +++ b/ansible/roles/users/tasks/main.yml @@ -1,10 +1,7 @@ --- -- name: "Configure users on {{ ansible_facts['distribution'] }} guest operating system." + +- name: "{{ task_name }}" include_tasks: linux.yml - when: "ansible_facts['distribution'] == 'Debian'" -- name: "Configure users on {{ ansible_facts['distribution'] }} guest operating system." - include_tasks: linux.yml - when: "ansible_facts['distribution'] == 'Ubuntu'" -- name: "Configure users on {{ ansible_facts['distribution'] }} guest operating system." - include_tasks: linux.yml - when: "ansible_facts['distribution'] in ['RedHat', 'CentOS', 'Rocky', 'AlmaLinux', 'OracleLinux']" + when: ansible_os_family in ['Debian', 'RedHat', 'Suse'] + +... \ No newline at end of file diff --git a/builds/linux/opensuse/leap-15-5/data/autoinst.pkrtpl.hcl b/builds/linux/opensuse/leap-15-5/data/autoinst.pkrtpl.hcl new file mode 100644 index 0000000..8506552 --- /dev/null +++ b/builds/linux/opensuse/leap-15-5/data/autoinst.pkrtpl.hcl @@ -0,0 +1,625 @@ + + + + + + + repo-backports-update + http://download.opensuse.org/update/leap/15.5/backports/ + Update repository of openSUSE Backports + 99 + / + + + repo-non-oss + http://download.opensuse.org/distribution/leap/15.5/repo/non-oss/ + Non-OSS Repository + 99 + / + + + repo-openh264 + http://codecs.opensuse.org/openh264/openSUSE_Leap/ + Open H.264 Codec (openSUSE Leap) + 99 + + + + repo-sle-update + http://download.opensuse.org/update/leap/15.5/sle/ + Update repository with updates from SUSE Linux Enterprise 15 + 99 + / + + + repo-update + http://download.opensuse.org/update/leap/15.5/oss + Main Update Repository + 99 + / + + + repo-update-non-oss + http://download.opensuse.org/update/leap/15.5/non-oss/ + Update Repository (Non-Oss) + 99 + / + + + + + + splash=silent preempt=full mitigations=auto quiet security=apparmor + auto + auto + false + true + true + gfxterm + 8 + false + true + vga=gfx-1024x768x16 + + grub2 + + + false + + + public + true + off + true + + + Unsolicited incoming network packets are rejected. Incoming packets that are related to outgoing network connections are accepted. Outgoing network connections are allowed. + + false + block + + + + Block + %%REJECT%% + + + For computers in your demilitarized zone that are publicly-accessible with limited access to your internal network. Only selected incoming connections are accepted. + + false + dmz + + + + ssh + + DMZ + default + + + All network connections are accepted. + + docker0 + + false + docker + + + + docker + ACCEPT + + + Unsolicited incoming network packets are dropped. Incoming packets that are related to outgoing network connections are accepted. Outgoing network connections are allowed. + + false + drop + + + + Drop + DROP + + + For use on external networks. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + true + external + + + + ssh + + External + default + + + For use in home areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + false + home + + + + dhcpv6-client + mdns + samba-client + ssh + + Home + default + + + For use on internal networks. You mostly trust the other computers on the networks to not harm your computer. Only selected incoming connections are accepted. + + false + internal + + + + dhcpv6-client + mdns + samba-client + ssh + + Internal + default + + + For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + eth0 + + false + public + + + + dhcpv6-client + ssh + + Public + default + + + All network connections are accepted. + + false + trusted + + + + Trusted + ACCEPT + + + For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + false + work + + + + dhcpv6-client + ssh + + Work + default + + + + + + false + + + + + 100 + users + + + + 493 + utmp + + + + 65533 + nogroup + + + + 71 + ntadmin + + + + 488 + input + + + + 491 + cdrom + + + + 475 + polkitd + + + + 1 + bin + daemon + + + 2 + daemon + + + + 65534 + nobody + + + + 36 + kvm + + + + 59 + maildrop + postfix + + + 477 + sshd + + + + 482 + chrony + + + + 489 + disk + + + + 492 + audio + + + + 494 + lock + + + + 15 + shadow + + + + 485 + tape + + + + 495 + kmem + + + + 5 + tty + + + + 480 + systemd-network + + + + 484 + video + + + + 499 + messagebus + + + + 486 + sgx + + + + 497 + lp + + + + 487 + render + + + + 0 + root + + + + 42 + trusted + + + + 479 + systemd-timesync + + + + 481 + systemd-journal + + + + 51 + postfix + + + + 490 + dialout + + + + 483 + audit + + + + 498 + mail + postfix + + + 62 + man + + + + 496 + wheel + + + + 478 + nscd + + + + + + + 127.0.0.1 + + localhost + + + + ::1 + + localhost ipv6-localhost ipv6-loopback + + + + fe00::0 + + ipv6-localnet + + + + ff00::0 + + ipv6-mcastprefix + + + + ff02::1 + + ipv6-allnodes + + + + ff02::2 + + ipv6-allrouters + + + + ff02::3 + + ipv6-allhosts + + + + + + + + AUTO + + + true + localhost + auto + + + + dhcp + eth0 + auto + public + + + true + true + false + + + eth0 + ATTR{address} + bc:24:11:b0:93:4b + + + + false + false + + + + auto + + systemd + +${storage} + + false + + + multi-user + + + YaST2-Firstboot + YaST2-Second-Stage + apparmor + auditd + klog + chronyd + cron + cups + firewalld + wickedd-auto4 + wickedd-dhcp4 + wickedd-dhcp6 + wickedd-nanny + irqbalance + issue-generator + kbdsettings + lvm2-monitor + mcelog + wicked + nscd + postfix + purge-kernels + rsyslog + smartd + sshd + systemd-fsck-root + systemd-pstore + systemd-remount-fs + qemu-guest-agent + + + + + true + + + wicked + os-prober + openssh + openSUSE-release + lvm2 + kexec-tools + grub2 + glibc + firewalld + e2fsprogs + chrony + autoyast2 + qemu-guest-agent + + + apparmor + base + documentation + enhanced_base + minimal_base + sw_management + yast2_basis + + + Leap + + + + false + false + + + ${vm_os_timezone} + + + + 100 + /home + -1 + /bin/bash + 022 + + + + + true + Build User + 100 + /home/${build_username} + false + + + + + 99999 + 0 + 7 + + /bin/bash + 1000 + ${build_password_encrypted} + ${build_username} + + + + + + + + + + + diff --git a/builds/linux/opensuse/leap-15-5/data/storage.pkrtpl.hcl b/builds/linux/opensuse/leap-15-5/data/storage.pkrtpl.hcl new file mode 100644 index 0000000..8fdf239 --- /dev/null +++ b/builds/linux/opensuse/leap-15-5/data/storage.pkrtpl.hcl @@ -0,0 +1,63 @@ + + + /dev/system + false + + + true + ext4 + false + root + / + device + false + false + 32199671808 + + 1 + 0 + + + true + swap + false + swap + swap + device + false + false + 2147483648 + + 1 + 0 + + + 4194304 + CT_LVM + + + /dev/${device} + gpt + + + true + false + 263 + 1 + false + 8388608 + + + true + false + system + 142 + 2 + false + 34350284288 + + + CT_DISK + all + + \ No newline at end of file diff --git a/builds/linux/opensuse/leap-15-5/linux-opensuse-leap.auto.pkrvars.hcl b/builds/linux/opensuse/leap-15-5/linux-opensuse-leap.auto.pkrvars.hcl new file mode 100644 index 0000000..3e954b0 --- /dev/null +++ b/builds/linux/opensuse/leap-15-5/linux-opensuse-leap.auto.pkrvars.hcl @@ -0,0 +1,45 @@ +/* + DESCRIPTION: + Ubuntu Server 22.04 LTS variables used by the Packer Plugin for Proxmox (proxmox-iso). +*/ + +// Guest Operating System Metadata +vm_os_language = "en_US" +vm_os_keyboard = "us" +vm_os_timezone = "UTC" +vm_os_family = "linux" +vm_os_name = "opensuse-leap" +vm_os_version = "15.5" + +// Virtual Machine Guest Operating System Setting +vm_os_type = "l26" + +// Virtual Machine Hardware Settings +vm_bios = "seabios" +vm_cpu_count = 1 +vm_cpu_sockets = 1 +vm_cpu_type = "x86-64-v2-AES" +vm_mem_size = 2048 +vm_disk_type = "virtio" +vm_disk_size = "32G" +vm_disk_format = "raw" +vm_storage_pool = "vm-data" +vm_disk_controller_type = "virtio-scsi-pci" +vm_network_card_model = "virtio" +vm_bridge_interface = "vmbr0" +vm_vlan_tag = "102" + +// Removable Media Settings +iso_path = "iso" +iso_file = "openSUSE-Leap-15.5-DVD-x86_64-Media.iso" +iso_checksum = "file:https://download.opensuse.org/distribution/leap/15.5/iso/openSUSE-Leap-15.5-DVD-x86_64-Media.iso.sha256" + +// Boot Settings +vm_boot = "order=virtio0;ide2;net0" +vm_boot_wait = "5s" + +// EFI Settings +vm_firmware_path = "./OVMF.fd" +vm_efi_storage_pool = "vm-data" +vm_efi_pre_enrolled_keys = false +vm_efi_type = "4m" diff --git a/builds/linux/opensuse/leap-15-5/linux-opensuse-leap.pkr.hcl b/builds/linux/opensuse/leap-15-5/linux-opensuse-leap.pkr.hcl new file mode 100644 index 0000000..b506b35 --- /dev/null +++ b/builds/linux/opensuse/leap-15-5/linux-opensuse-leap.pkr.hcl @@ -0,0 +1,202 @@ +/* + DESCRIPTION: + openSUSE-Leap 15.5 template using the Packer Builder for Proxmox (proxmox-iso). +*/ + +// BLOCK: packer +// The Packer configuration. + +packer { + required_version = ">= 1.9.1" + required_plugins { + ansible = { + source = "github.com/hashicorp/ansible" + version = "~> 1" + } + git = { + version = ">= 0.4.2" + source = "github.com/ethanmdavidson/git" + } + proxmox = { + version = ">= 1.1.6" + source = "github.com/hashicorp/proxmox" + } + } +} + +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + +// BLOCK: locals +// Defines the local variables. + +locals { + build_by = "Built by: HashiCorp Packer ${packer.version}" + build_date = formatdate("DD-MM-YYYY hh:mm ZZZ", "${timestamp()}" ) + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}\nCloud-Init: ${var.vm_cloud_init_enable}" + vm_disk_type = var.vm_disk_type == "virtio" ? "vda" : "sda" + manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) + manifest_path = "${path.cwd}/manifests/" + manifest_output = "${local.manifest_path}${local.manifest_date}.json" + data_source_content = { + "/autoinst.xml" = templatefile("${abspath(path.root)}/data/autoinst.pkrtpl.hcl", { + build_username = var.build_username + build_password = var.build_password + build_password_encrypted = var.build_password_encrypted + vm_disk_type = local.vm_disk_type + vm_os_language = var.vm_os_language + vm_os_keyboard = var.vm_os_keyboard + vm_os_timezone = var.vm_os_timezone + common_data_source = var.common_data_source + # lvm needs to be here so late commands can access vg names + lvm = var.vm_disk_lvm + storage = templatefile("${abspath(path.root)}/data/storage.pkrtpl.hcl", { + device = var.vm_disk_device + swap = var.vm_disk_use_swap + partitions = var.vm_disk_partitions + lvm = var.vm_disk_lvm + vm_bios = var.vm_bios + }) + }) + } + data_source_command = var.common_data_source == "http" ? "autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/autoinst.xml" : " netsetup=dhcp autoyast=device://sr1/autoinst.xml" + vm_name = "${var.vm_os_family}-${var.vm_os_name}-${var.vm_os_version}" + vm_bios = var.vm_bios == "ovmf" ? var.vm_firmware_path : null +} + +// BLOCK: source +// Defines the builder configuration blocks. + +source "proxmox-iso" "linux-opensuse-leap" { + + // Proxmox Connection Settings and Credentials + proxmox_url = "https://${var.proxmox_hostname}:8006/api2/json" + username = "${var.proxmox_api_token_id}" + token = "${var.proxmox_api_token_secret}" + insecure_skip_tls_verify = "${var.proxmox_insecure_connection}" + + // Proxmox Settings + node = "${var.proxmox_node}" + + // Virtual Machine Settings + vm_name = "${local.vm_name}" + bios = "${var.vm_bios}" + sockets = "${var.vm_cpu_sockets}" + cores = "${var.vm_cpu_count}" + cpu_type = "${var.vm_cpu_type}" + memory = "${var.vm_mem_size}" + os = "${var.vm_os_type}" + scsi_controller = "${var.vm_disk_controller_type}" + disks { + disk_size = "${var.vm_disk_size}" + type = "${var.vm_disk_type}" + storage_pool = "${var.vm_storage_pool}" + format = "${var.vm_disk_format}" + } + dynamic "efi_config" { + for_each = var.vm_bios == "ovmf" ? [1] : [] + content { + efi_storage_pool = var.vm_bios == "ovmf" ? var.vm_efi_storage_pool : null + efi_type = var.vm_bios == "ovmf" ? var.vm_efi_type : null + pre_enrolled_keys = var.vm_bios == "ovmf" ? var.vm_efi_pre_enrolled_keys : null + } + } + unmount_iso = true + ssh_username = "${var.build_username}" + ssh_password = "${var.build_password}" + ssh_timeout = "${var.timeout}" + ssh_port = "22" + iso_file = "${var.common_iso_storage}:${var.iso_path}/${var.iso_file}" + iso_checksum = "${var.iso_checksum}" + qemu_agent = true + + network_adapters { + bridge = "${var.vm_bridge_interface}" + model = "${var.vm_network_card_model}" + vlan_tag = "${var.vm_vlan_tag}" + } + + // Removable Media Settings + http_content = "${var.common_data_source}" == "http" ? "${local.data_source_content}" : null + + // Boot and Provisioning Settings + http_bind_address = var.common_data_source == "http" ? var.common_http_bind_address : null + http_port_min = var.common_data_source == "http" ? var.common_http_port_min : null + http_port_max = var.common_data_source == "http" ? var.common_http_port_max : null + boot = var.vm_boot + boot_wait = var.vm_boot_wait + boot_command = [ + "", + "linux ", + "biosdevname=0 ", + "net.ifnames=0 ", + "netdevice=eth0 ", + "netsetup=dhcp ", + "lang=en_US ", + "textmode=1 ", + "${local.data_source_command}", + "", + ] + + dynamic "additional_iso_files" { + for_each = var.common_data_source == "disk" ? [1] : [] + content { + cd_files = var.common_data_source == "disk" ? local.data_source_content : null + cd_label = var.common_data_source == "disk" ? "cidata" : null + iso_storage_pool = var.common_data_source == "disk" ? "local" : null + } + } + + template_name = "${local.vm_name}" + template_description = "${local.build_description}" + + # VM Cloud Init Settings + cloud_init = var.vm_cloud_init_enable + cloud_init_storage_pool = var.vm_cloud_init_enable == true ? var.vm_storage_pool : null + +} + +# Build Definition to create the VM Template +build { + sources = ["source.proxmox-iso.linux-opensuse-leap"] + + provisioner "ansible" { + playbook_file = "${path.cwd}/ansible/main.yml" + roles_path = "${path.cwd}/ansible/roles" + ansible_env_vars = [ + "ANSIBLE_CONFIG=${path.cwd}/ansible/ansible.cfg", + "ANSIBLE_PYTHON_INTERPRETER=/usr/bin/python3" + ] + extra_arguments = [ + "--extra-vars", "display_skipped_hosts=false", + "--extra-vars", "BUILD_USERNAME=${var.build_username}", + "--extra-vars", "BUILD_SECRET='${var.build_key}'", + "--extra-vars", "ANSIBLE_USERNAME=${var.ansible_username}", + "--extra-vars", "ANSIBLE_SECRET='${var.ansible_key}'", + ] + } + + post-processor "manifest" { + output = local.manifest_output + strip_path = true + strip_time = true + custom_data = { + ansible_username = "${var.ansible_username}" + build_username = "${var.build_username}" + build_date = "${local.build_date}" + build_version = "${local.build_version}" + common_data_source = "${var.common_data_source}" + vm_cpu_sockets = "${var.vm_cpu_sockets}" + vm_cpu_count = "${var.vm_cpu_count}" + vm_disk_size = "${var.vm_disk_size}" + vm_bios = "${var.vm_bios}" + vm_os_type = "${var.vm_os_type}" + vm_mem_size = "${var.vm_mem_size}" + vm_network_card_model = "${var.vm_network_card_model}" + vm_cloud_init_enable = "${var.vm_cloud_init_enable}" + } + } +} diff --git a/builds/linux/opensuse/leap-15-5/variables-storage.pkr.hcl b/builds/linux/opensuse/leap-15-5/variables-storage.pkr.hcl new file mode 100644 index 0000000..47eca29 --- /dev/null +++ b/builds/linux/opensuse/leap-15-5/variables-storage.pkr.hcl @@ -0,0 +1,53 @@ +/* + DESCRIPTION: + Debian 11 storage variables used by the Packer Plugin for Proxmox (proxmox-iso). +*/ + +// VM Storage Settings + +variable "vm_disk_device" { + type = string + description = "The device for the virtual disk. (e.g. 'sda')" +} + +variable "vm_disk_use_swap" { + type = bool + description = "Whether to use a swap partition." +} + +variable "vm_disk_partitions" { + type = list(object({ + name = string + size = number + format = object({ + label = string + fstype = string + }) + mount = object({ + path = string + options = string + }) + volume_group = string + })) + description = "The disk partitions for the virtual disk." +} + +variable "vm_disk_lvm" { + type = list(object({ + name = string + partitions = list(object({ + name = string + size = number + format = object({ + label = string + fstype = string + }) + mount = object({ + path = string + options = string + }) + })) + })) + description = "The LVM configuration for the virtual disk." + default = [] +} diff --git a/builds/linux/opensuse/leap-15-5/variables.pkr.hcl b/builds/linux/opensuse/leap-15-5/variables.pkr.hcl new file mode 100644 index 0000000..e5c9f66 --- /dev/null +++ b/builds/linux/opensuse/leap-15-5/variables.pkr.hcl @@ -0,0 +1,297 @@ +/* + DESCRIPTION: + Debian 11 variables using the Packer Builder for Proxmox (proxmox-iso). +*/ + +// BLOCK: variable +// Defines the input variables. + +// Proxmox Credentials + +variable "proxmox_hostname" { + type = string + description = "The FQDN or IP address of a Proxmox node. Only one node should be specified in a cluster." +} + +variable "proxmox_api_token_id" { + type = string + description = "The token to login to the Proxmox node/cluster. The format is USER@REALM!TOKENID. (e.g. packer@pam!packer_pve_token)" +} + +variable "proxmox_api_token_secret" { + type = string + description = "The secret for the API token used to login to the Proxmox API." +# sensitive = true +} + +variable "proxmox_insecure_connection" { + description = "true/false to skip Proxmox TLS certificate checks." + type = bool + default = true +} + +// Proxmox Settings + +variable "proxmox_node" { + type = string + description = "The name of the Proxmox node that Packer will build templates on." +} + +// Virtual Machine Settings + +variable "vm_os_language" { + type = string + description = "The guest operating system language." + default = "en_US" +} + +variable "vm_os_keyboard" { + type = string + description = "The guest operating system keyboard layout." + default = "us" +} + +variable "vm_os_timezone" { + type = string + description = "The guest operating system timezone." + default = "UTC" +} + +variable "vm_os_family" { + type = string + description = "The guest operating system family. Used for naming. (e.g. 'linux')" +} + +variable "vm_os_name" { + type = string + description = "The guest operating system name. Used for naming. (e.g. 'ubuntu')" +} + +variable "vm_os_version" { + type = string + description = "The guest operating system version. Used for naming. (e.g. '22-04-lts')" +} + +variable "vm_os_type" { + type = string + description = "The guest operating system type. (e.g. 'l26')" +} + +variable "vm_bios" { + type = string + description = "The firmware type. Allowed values 'ovmf' or 'seabios'" + default = "OVMF" + + validation { + condition = contains(["ovmf", "seabios"], var.vm_bios) + error_message = "The vm_bios value must be 'ovmf' or 'seabios'." + } +} + +variable "vm_firmware_path" { + type = string + description = "The firmware file to be used. Needed for EFI" + default = "/usr/share/ovmf/OVMF.fd" +} + +variable "vm_efi_storage_pool" { + type = string + description = "Set the UEFI disk storage location. (e.g. 'local-lvm')" +} + +variable "vm_efi_type" { + type = string + description = "Specifies the version of the OVMF firmware to be used. (e.g. '4m')" +} + +variable "vm_efi_pre_enrolled_keys" { + type = bool + description = "Whether Microsoft Standard Secure Boot keys should be pre-loaded on the EFI disk. (e.g. false)" +} + +variable "vm_cpu_count" { + type = number + description = "The number of virtual CPUs. (e.g. '2')" +} + +variable "vm_cpu_sockets" { + type = number + description = "The number of virtual CPU sockets. (e.g. '1')" +} + +variable "vm_cpu_type" { + type = string + description = "The CPU type to emulate. See the Proxmox API documentation for the complete list of accepted values. For best performance, set this to host. Defaults to kvm64." +} + +variable "vm_mem_size" { + type = number + description = "The size for the virtual memory in MB. (e.g. '2048')" +} + +variable "vm_disk_controller_type" { + type = string + description = "The SCSI controller model to emulate. (e.g. 'virtio-scsi-pci')" +} + +variable "vm_disk_type" { + type = string + description = "The type of disk to emulate. (e.g. 'virtio')" +} + +variable "vm_storage_pool" { + type = string + description = "The name of the Proxmox storage pool to store the VM template. (e.g. 'local-lvm')" +} + +variable "vm_disk_size" { + type = string + description = "The size for the virtual disk in GB. (e.g. '32G')" +} + +variable "vm_disk_format" { + type = string + description = "The format of the file backing the disk. (e.g. 'qcow2')" +} + +variable "vm_network_card_model" { + type = string + description = "The model of the virtual network adapter to emulate. (e.g. 'virtio')" +} + +variable "vm_bridge_interface" { + type = string + description = "The name of the Proxmox bridge to attach the adapter to." +} + +variable "vm_vlan_tag" { + type = string + description = "If the adapter should tag packets, give the VLAN ID. (e.g. '102')" +} + +// Cloud-Init Settings + +variable "vm_cloud_init_enable" { + type = bool + description = "Enable or disable cloud-init drive in Proxmox. (e.g. false)" + default = false +} + +// Removable Media Settings + +variable "common_iso_storage" { + type = string + description = "The name of the source Proxmox storage location for ISO images. (e.g. 'local-lvm')" +} + +variable "iso_path" { + type = string + description = "The path on the source Proxmox storage location for ISO images. (e.g. 'iso')" +} + +variable "iso_file" { + type = string + description = "The file name of the ISO image used by the vendor. (e.g. 'ubuntu--live-server-amd64.iso')" +} + +variable "iso_checksum" { + type = string + description = "The checksum value of the ISO image provided by the vendor." +} + +// Boot Settings + +variable "common_data_source" { + type = string + description = "The provisioning data source. (e.g. 'http' or 'disk')" +} + +variable "common_http_bind_address" { + type = string + description = "Define an IP address on the host to use for the HTTP server." + default = null +} + +variable "common_http_port_min" { + type = number + description = "The start of the HTTP port range." +} + +variable "common_http_port_max" { + type = number + description = "The end of the HTTP port range." +} + +variable "vm_boot" { + type = string + description = "The boot order for virtual machine devices. (e.g. 'order=virtio0;ide2;net0')" +} + +variable "vm_boot_wait" { + type = string + description = "The time to wait after booting the initial VM before typing the boot_command (e.g '10s')" +} + +variable "common_ip_wait_timeout" { + type = string + description = "Time to wait for guest operating system IP address response." +} + +variable "common_shutdown_timeout" { + type = string + description = "Time to wait for guest operating system shutdown." +} + +// Communicator Settings and Credentials + +variable "build_username" { + type = string + description = "The username to login to the guest operating system. (e.g. 'ubuntu')" +# sensitive = true +} + +variable "build_password" { + type = string + description = "The password to login to the guest operating system." +# sensitive = true +} + +variable "build_password_encrypted" { + type = string + description = "The encrypted password to login to the guest operating system." +# sensitive = true +} + +variable "build_key" { + type = string + description = "The SSH public key to login to the guest operating system." +# sensitive = true +} + +variable "timeout" { + description = "not sure why I need so high a timeout but here we are" + default = "90m" +} + +// Ansible Credentials + +variable "ansible_username" { + type = string + description = "The username for Ansible to login to the guest operating system. (e.g. 'ansible')" +# sensitive = true +} + +variable "ansible_key" { + type = string + description = "The public key for Ansible to login to the guest operating system." +# sensitive = true +} + +// HCP Packer Settings + +variable "common_hcp_packer_registry_enabled" { + type = bool + description = "Enable the HCP Packer registry." + default = false +} +