From b3524c0b1aa80980c07583640d9edca98129bf12 Mon Sep 17 00:00:00 2001 From: Iwan Clement Date: Mon, 27 Dec 2021 21:28:04 +0100 Subject: [PATCH] Files creation --- data/20.04.pkrvars.hcl | 39 ++++++++ data/Linux.pkr.hcl | 203 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 data/20.04.pkrvars.hcl create mode 100644 data/Linux.pkr.hcl diff --git a/data/20.04.pkrvars.hcl b/data/20.04.pkrvars.hcl new file mode 100644 index 0000000..f78f223 --- /dev/null +++ b/data/20.04.pkrvars.hcl @@ -0,0 +1,39 @@ +username = "proxmox_user" +password = "tvowyfv9gh23sdfAERtLWav2674" +proxmox_url = "https://192.168.111.34:8006/api2/json" +node = "grosnoeud" +iso_file = "" +os_version = "20.04" +os_family = "ubuntu" +guest_os_type = "ubuntu64Guest" +os_iso_path = "[SATAStorage] ISO/ubuntu-20.04-legacy-server-amd64.iso" +os_iso_url = "http://cdimage.ubuntu.com/ubuntu-legacy-server/releases/20.04/release/ubuntu-20.04-legacy-server-amd64.iso"` +iso_checksum = "36f15879bd9dfd061cd588620a164a82972663fdd148cce1f70d57d314c21b73" +root_disk_size = 24000 +connection_username = "vagrant" +connection_password = "vagrant" +boot_command = [ + "", + "", + "", + "/install/vmlinuz", + " auto=true", + " url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", + " locale=en_US", + " console-setup/ask_detect=false", + " console-setup/layoutcode=us", + " console-setup/modelcode=pc105", + " debconf/frontend=noninteractive", + " debian-installer=en_US", + " fb=false", + " initrd=/install/initrd.gz", + " kbd-chooser/method=us", + " keyboard-configuration/layout=USA", + " keyboard-configuration/variant=USA", + " netcfg/get_domain=vm", + " netcfg/get_hostname=packer", + " grub-installer/bootdev=/dev/sda", + " noapic", + " -- ", + "" +] \ No newline at end of file diff --git a/data/Linux.pkr.hcl b/data/Linux.pkr.hcl new file mode 100644 index 0000000..e096c70 --- /dev/null +++ b/data/Linux.pkr.hcl @@ -0,0 +1,203 @@ +source "proxmox-iso" "windows" { + # vCenter settings + vcenter_server = var.vcenter_server + username = var.vcenter_username + password = var.vcenter_password + insecure_connection = true #TODO: Add ca to docker + cluster = var.vcenter_cluster + datacenter = var.vcenter_datacenter + host = var.vcenter_host + datastore = var.vcenter_datastore + convert_to_template = true + folder = var.vcenter_folder + + # VM Settings + ip_wait_timeout = "45m" + communicator = "winrm" + winrm_username = var.connection_username + winrm_password = var.connection_password + winrm_timeout = "12h" + winrm_port = "5985" + shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"" + shutdown_timeout = "15m" + vm_version = var.vm_hardware_version + iso_paths = [ + var.os_iso_path + ] + iso_checksum = var.iso_checksum + vm_name = "server-${ var.os_version }-{{ isotime \"2006-01-02\" }}" + guest_os_type = var.guest_os_type + disk_controller_type = ["pvscsi"] # Windows requires vmware tools drivers for pvscsi to work + network_adapters { + # For windows, the vmware tools network drivers are required to be connected by floppy before tools is installed + network = var.vm_network + network_card = var.nic_type + } + storage { + disk_size = var.root_disk_size + disk_thin_provisioned = true + } + CPUs = var.num_cpu + cpu_cores = var.num_cores + CPU_hot_plug = true + RAM = var.vm_ram + RAM_hot_plug = true + floppy_files = [ + "./boot_config/${var.os_version}/Autounattend.xml", + "./scripts/winrm.bat", + "./scripts/Install-VMWareTools.ps1", + "./drivers/" + ] +} +source "proxmox-iso" "ubuntu" { + # vCenter settings + vcenter_server = var.vcenter_server + username = var.vcenter_username + password = var.vcenter_password + insecure_connection = true #TODO: Add ca to docker + cluster = var.vcenter_cluster + datacenter = var.vcenter_datacenter + host = var.vcenter_host + datastore = var.vcenter_datastore + convert_to_template = true + folder = var.vcenter_folder + + # VM Settings + ip_wait_timeout = "45m" + ssh_username = var.connection_username + ssh_password = var.connection_password + ssh_timeout = "12h" + ssh_port = "22" + ssh_handshake_attempts = "20" + shutdown_timeout = "15m" + vm_version = var.vm_hardware_version + iso_paths = [var.os_iso_path] + iso_checksum = var.iso_checksum + vm_name = "${ var.os_family }-${ var.os_version }-{{ isotime \"2006-01-02\" }}" + guest_os_type = var.guest_os_type + disk_controller_type = ["pvscsi"] + network_adapters { + network = var.vm_network + network_card = var.nic_type + } + storage { + disk_size = var.root_disk_size + disk_thin_provisioned = true + } + CPUs = var.num_cpu + cpu_cores = var.num_cores + CPU_hot_plug = true + RAM = var.vm_ram + RAM_hot_plug = true + boot_wait = "5s" + boot_command = var.boot_command +} + +source "proxmox-iso" "centos" { + # vCenter settings + vcenter_server = var.vcenter_server + username = var.vcenter_username + password = var.vcenter_password + insecure_connection = true #TODO: Add ca to docker + cluster = var.vcenter_cluster + datacenter = var.vcenter_datacenter + host = var.vcenter_host + datastore = var.vcenter_datastore + convert_to_template = true + folder = var.vcenter_folder + + # VM Settings + ip_wait_timeout = "45m" + ssh_username = var.connection_username + ssh_password = var.connection_password + ssh_timeout = "12h" + ssh_port = "22" + ssh_handshake_attempts = "20" + shutdown_timeout = "15m" + vm_version = var.vm_hardware_version + iso_paths = [var.os_iso_path] + iso_checksum = var.iso_checksum + vm_name = "${ var.os_family }-${ var.os_version }-{{ isotime \"2006-01-02\" }}" + guest_os_type = var.guest_os_type + disk_controller_type = ["pvscsi"] + network_adapters { + network = var.vm_network + network_card = var.nic_type + } + storage { + disk_size = var.root_disk_size + disk_thin_provisioned = true + } + CPUs = var.num_cpu + cpu_cores = var.num_cores + CPU_hot_plug = true + RAM = var.vm_ram + RAM_hot_plug = true + boot_wait = "5s" + boot_command = var.boot_command +} + +build { + # Windows builds + sources = [ + "source.proxmox-iso.windows", + ] + provisioner "powershell" { + elevated_user = var.connection_username + elevated_password = var.connection_password + scripts = [ + "scripts/Disable-UAC.ps1" # I re-enable UAC with ansible post deployment + ] + } + provisioner "windows-update" { # This requires windows-update-provisioner https://github.com/rgl/packer-provisioner-windows-update + pause_before = "30s" + filters = [ + "exclude:$_.Title -like '*VMware*'", + "exclude:$_.Title -like '*Preview*'", + "exclude:$_.Title -like '*Defender*'", + "include:$true" + ] + } + provisioner "powershell" { + elevated_user = var.connection_username + elevated_password = var.connection_password + scripts = [ + "scripts/Remove-UpdateCache.ps1", + "scripts/Invoke-Defrag.ps1", + "scripts/Reset-EmptySpace.ps1" + ] + } +} + +build { + sources = [ + "source.proxmox-iso.ubuntu", + ] + provisioner "shell" { + execute_command = "echo '${var.connection_password}' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'" # This runs the scripts with sudo + scripts = [ + "scripts/apt.sh", + "scripts/cleanup.sh", + "scripts/python.sh", + "scripts/ansible.sh", + "scripts/ubuntu-prep.sh", + "scripts/clean-ssh-hostkeys.sh" + ] + } +} + +build { + sources = [ + "source.proxmox-iso.centos", + ] + provisioner "shell" { + execute_command = "echo '${var.connection_password}' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'" # This runs the scripts with sudo + scripts = [ + "scripts/ansible-centos.sh", + "scripts/vmware-centos.sh", + "scripts/yum-update.sh", + "scripts/cleanup-centos.sh", + "scripts/clean-ssh-hostkeys.sh" + ] + } +} \ No newline at end of file