From ba1ad9ea1592b77f8908cbe127ad4d41c7e1b4a0 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 5 Feb 2021 04:21:29 -0800 Subject: [PATCH] Vsphere example update (#10574) * fix ubuntu json template example * add hcl template example * add hcl alpine example * add hcl versions of alpine and macos; update macos json * add hcl version of windows template, call fix on windows json --- .../vsphere/examples/alpine/alpine-3.8.json | 68 +++++++++--------- .../examples/alpine/alpine-3.8.pkr.hcl | 44 ++++++++++++ builder/vsphere/examples/clone/alpine.pkr.hcl | 25 +++++++ .../vsphere/examples/macos/macos-10.13.json | 67 +++++++++--------- .../examples/macos/macos-10.13.pkr.hcl | 43 ++++++++++++ .../vsphere/examples/ubuntu/ubuntu-16.04.json | 69 ++++++++++--------- .../examples/ubuntu/ubuntu-16.04.pkr.hcl | 52 ++++++++++++++ .../vsphere/examples/windows/windows-10.json | 64 ++++++++--------- .../examples/windows/windows-10.pkr.hcl | 41 +++++++++++ 9 files changed, 340 insertions(+), 133 deletions(-) create mode 100644 builder/vsphere/examples/alpine/alpine-3.8.pkr.hcl create mode 100644 builder/vsphere/examples/clone/alpine.pkr.hcl create mode 100644 builder/vsphere/examples/macos/macos-10.13.pkr.hcl create mode 100644 builder/vsphere/examples/ubuntu/ubuntu-16.04.pkr.hcl create mode 100644 builder/vsphere/examples/windows/windows-10.pkr.hcl diff --git a/builder/vsphere/examples/alpine/alpine-3.8.json b/builder/vsphere/examples/alpine/alpine-3.8.json index e2aca3924..f16895dcc 100644 --- a/builder/vsphere/examples/alpine/alpine-3.8.json +++ b/builder/vsphere/examples/alpine/alpine-3.8.json @@ -2,34 +2,9 @@ "builders": [ { "type": "vsphere-iso", - - "vcenter_server": "vcenter.vsphere65.test", - "username": "root", - "password": "jetbrains", - "insecure_connection": true, - - "vm_name": "alpine-{{timestamp}}", - "host": "esxi-1.vsphere65.test", - - "CPUs": 1, - "RAM": 512, + "CPUs": 1, + "RAM": 512, "RAM_reserve_all": true, - "disk_controller_type": "pvscsi", - "disk_size": 1024, - "disk_thin_provisioned": true, - "network_card": "vmxnet3", - - "guest_os_type": "other3xLinux64Guest", - - "iso_paths": [ - "[datastore1] ISO/alpine-standard-3.8.2-x86_64.iso" - ], - "floppy_files": [ - "{{template_dir}}/answerfile", - "{{template_dir}}/setup.sh" - ], - - "boot_wait": "15s", "boot_command": [ "root", "mount -t vfat /dev/fd0 /media/floppy", @@ -47,16 +22,43 @@ "mount -t vfat /dev/fd0 /media/floppy", "/media/floppy/SETUP.SH" ], - + "boot_wait": "15s", + "disk_controller_type": "pvscsi", + "floppy_files": [ + "{{template_dir}}/answerfile", + "{{template_dir}}/setup.sh" + ], + "guest_os_type": "other3xLinux64Guest", + "host": "esxi-1.vsphere65.test", + "insecure_connection": true, + "iso_paths": [ + "[datastore1] ISO/alpine-standard-3.8.2-x86_64.iso" + ], + "network_adapters": [ + { + "network_card": "vmxnet3" + } + ], + "password": "jetbrains", + "ssh_password": "jetbrains", "ssh_username": "root", - "ssh_password": "jetbrains" + "storage": [ + { + "disk_size": 1024, + "disk_thin_provisioned": true + } + ], + "username": "root", + "vcenter_server": "vcenter.vsphere65.test", + "vm_name": "alpine-{{timestamp}}" } ], - "provisioners": [ { - "type": "shell", - "inline": ["ls /"] + "inline": [ + "ls /" + ], + "type": "shell" } ] -} +} \ No newline at end of file diff --git a/builder/vsphere/examples/alpine/alpine-3.8.pkr.hcl b/builder/vsphere/examples/alpine/alpine-3.8.pkr.hcl new file mode 100644 index 000000000..a4879333b --- /dev/null +++ b/builder/vsphere/examples/alpine/alpine-3.8.pkr.hcl @@ -0,0 +1,44 @@ +# "timestamp" template function replacement +locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } + +# source blocks are analogous to the "builders" in json templates. They are used +# in build blocks. A build block runs provisioners and post-processors on a +# source. Read the documentation for source blocks here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/source +source "vsphere-iso" "autogenerated_1" { + CPUs = 1 + RAM = 512 + RAM_reserve_all = true + boot_command = ["root", "mount -t vfat /dev/fd0 /media/floppy", "setup-alpine -f /media/floppy/answerfile", "", "jetbrains", "jetbrains", "", "y", "", "reboot", "", "root", "jetbrains", "mount -t vfat /dev/fd0 /media/floppy", "/media/floppy/SETUP.SH"] + boot_wait = "15s" + disk_controller_type = ["pvscsi"] + floppy_files = ["${path.root}/answerfile", "${path.root}/setup.sh"] + guest_os_type = "other3xLinux64Guest" + host = "esxi-1.vsphere65.test" + insecure_connection = true + iso_paths = ["[datastore1] ISO/alpine-standard-3.8.2-x86_64.iso"] + network_adapters { + network_card = "vmxnet3" + } + password = "jetbrains" + ssh_password = "jetbrains" + ssh_username = "root" + storage { + disk_size = 1024 + disk_thin_provisioned = true + } + username = "root" + vcenter_server = "vcenter.vsphere65.test" + vm_name = "alpine-${local.timestamp}" +} + +# a build block invokes sources and runs provisioning steps on them. The +# documentation for build blocks can be found here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/build +build { + sources = ["source.vsphere-iso.autogenerated_1"] + + provisioner "shell" { + inline = ["ls /"] + } +} diff --git a/builder/vsphere/examples/clone/alpine.pkr.hcl b/builder/vsphere/examples/clone/alpine.pkr.hcl new file mode 100644 index 000000000..005bae47a --- /dev/null +++ b/builder/vsphere/examples/clone/alpine.pkr.hcl @@ -0,0 +1,25 @@ +# "timestamp" template function replacement +locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } + +# source blocks are analogous to the "builders" in json templates. They are used +# in build blocks. A build block runs provisioners and post-processors on a +# source. Read the documentation for source blocks here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/source +source "vsphere-clone" "example_clone" { + communicator = "none" + host = "esxi-1.vsphere65.test" + insecure_connection = "true" + password = "jetbrains" + template = "alpine" + username = "root" + vcenter_server = "vcenter.vsphere65.test" + vm_name = "alpine-clone-${local.timestamp}" +} + +# a build block invokes sources and runs provisioning steps on them. The +# documentation for build blocks can be found here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/build +build { + sources = ["source.vsphere-clone.example_clone"] + +} diff --git a/builder/vsphere/examples/macos/macos-10.13.json b/builder/vsphere/examples/macos/macos-10.13.json index b934dde46..22a02374d 100644 --- a/builder/vsphere/examples/macos/macos-10.13.json +++ b/builder/vsphere/examples/macos/macos-10.13.json @@ -2,49 +2,48 @@ "builders": [ { "type": "vsphere-iso", - - "vcenter_server": "vcenter.vsphere65.test", - "username": "root", - "password": "jetbrains", - "insecure_connection": "true", - - "vm_name": "macos-packer", - "host": "esxi-mac.vsphere65.test", - - "guest_os_type": "darwin16_64Guest", - - "CPUs": 1, - "RAM": 4096, - - "disk_size": 32768, - "disk_thin_provisioned": true, - - "network_card": "e1000e", - "usb_controller": true, - + "CPUs": 1, + "RAM": 4096, + "boot_command": [ + "", + "ut", + "/Volumes/setup/setup.sh" + ], + "boot_wait": "4m", + "cdrom_type": "sata", "configuration_parameters": { "ich7m.present": "TRUE", "smc.present": "TRUE" }, - "cdrom_type": "sata", - + "guest_os_type": "darwin16_64Guest", + "host": "esxi-mac.vsphere65.test", + "insecure_connection": "true", + "iso_checksum": "file:///{{template_dir}}/setup/out/sha256sums", "iso_paths": [ "[datastore-mac] ISO/macOS 10.13.3.iso", "[datastore-mac] ISO/VMware Tools/10.2.0/darwin.iso" ], - - "iso_urls": ["{{template_dir}}/setup/out/setup.iso"], - "iso_checksum": "file:///{{template_dir}}/setup/out/sha256sums", - - "boot_wait": "4m", - "boot_command": [ - "", - "ut", - "/Volumes/setup/setup.sh" + "iso_urls": [ + "{{template_dir}}/setup/out/setup.iso" + ], + "network_adapters": [ + { + "network_card": "e1000e" + } ], - + "password": "jetbrains", + "ssh_password": "jetbrains", "ssh_username": "jetbrains", - "ssh_password": "jetbrains" + "storage": [ + { + "disk_size": 32768, + "disk_thin_provisioned": true + } + ], + "usb_controller": true, + "username": "root", + "vcenter_server": "vcenter.vsphere65.test", + "vm_name": "macos-packer" } ] -} +} \ No newline at end of file diff --git a/builder/vsphere/examples/macos/macos-10.13.pkr.hcl b/builder/vsphere/examples/macos/macos-10.13.pkr.hcl new file mode 100644 index 000000000..544d37f12 --- /dev/null +++ b/builder/vsphere/examples/macos/macos-10.13.pkr.hcl @@ -0,0 +1,43 @@ +# source blocks are analogous to the "builders" in json templates. They are used +# in build blocks. A build block runs provisioners and post-processors on a +# source. Read the documentation for source blocks here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/source +source "vsphere-iso" "example_osx" { + CPUs = 1 + RAM = 4096 + boot_command = ["", "ut", "/Volumes/setup/setup.sh"] + boot_wait = "4m" + cdrom_type = "sata" + configuration_parameters = { + "ich7m.present" = "TRUE" + "smc.present" = "TRUE" + } + guest_os_type = "darwin16_64Guest" + host = "esxi-mac.vsphere65.test" + insecure_connection = "true" + iso_checksum = "file:///${path.root}/setup/out/sha256sums" + iso_paths = ["[datastore-mac] ISO/macOS 10.13.3.iso", "[datastore-mac] ISO/VMware Tools/10.2.0/darwin.iso"] + iso_urls = ["${path.root}/setup/out/setup.iso"] + network_adapters { + network_card = "e1000e" + } + password = "jetbrains" + ssh_password = "jetbrains" + ssh_username = "jetbrains" + storage { + disk_size = 32768 + disk_thin_provisioned = true + } + usb_controller = ["usb"] + username = "root" + vcenter_server = "vcenter.vsphere65.test" + vm_name = "macos-packer" +} + +# a build block invokes sources and runs provisioning steps on them. The +# documentation for build blocks can be found here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/build +build { + sources = ["source.vsphere-iso.example_osx"] + +} diff --git a/builder/vsphere/examples/ubuntu/ubuntu-16.04.json b/builder/vsphere/examples/ubuntu/ubuntu-16.04.json index 37f5299bd..f5c87b2c5 100644 --- a/builder/vsphere/examples/ubuntu/ubuntu-16.04.json +++ b/builder/vsphere/examples/ubuntu/ubuntu-16.04.json @@ -2,36 +2,9 @@ "builders": [ { "type": "vsphere-iso", - - "vcenter_server": "vcenter.vsphere65.test", - "username": "root", - "password": "jetbrains", - "insecure_connection": "true", - - "vm_name": "example-ubuntu", - "host": "esxi-1.vsphere65.test", - - "guest_os_type": "ubuntu64Guest", - - "ssh_username": "jetbrains", - "ssh_password": "jetbrains", - - "CPUs": 1, - "RAM": 1024, + "CPUs": 1, + "RAM": 1024, "RAM_reserve_all": true, - - "disk_controller_type": "pvscsi", - "disk_size": 32768, - "disk_thin_provisioned": true, - - "network_card": "vmxnet3", - - "iso_paths": [ - "[datastore1] ISO/ubuntu-16.04.3-server-amd64.iso" - ], - "floppy_files": [ - "{{template_dir}}/preseed.cfg" - ], "boot_command": [ "", "", @@ -49,14 +22,42 @@ " locale=en_US", " file=/media/preseed.cfg", "" - ] + ], + "disk_controller_type": "pvscsi", + "floppy_files": [ + "{{template_dir}}/preseed.cfg" + ], + "guest_os_type": "ubuntu64Guest", + "host": "esxi-1.vsphere65.test", + "insecure_connection": true, + "iso_paths": [ + "[datastore1] ISO/ubuntu-16.04.3-server-amd64.iso" + ], + "network_adapters": [ + { + "network_card": "vmxnet3" + } + ], + "password": "jetbrains", + "ssh_password": "jetbrains", + "ssh_username": "jetbrains", + "storage": [ + { + "disk_size": 32768, + "disk_thin_provisioned": true + } + ], + "username": "root", + "vcenter_server": "vcenter.vsphere65.test", + "vm_name": "example-ubuntu" } ], - "provisioners": [ { - "type": "shell", - "inline": ["ls /"] + "inline": [ + "ls /" + ], + "type": "shell" } ] -} +} \ No newline at end of file diff --git a/builder/vsphere/examples/ubuntu/ubuntu-16.04.pkr.hcl b/builder/vsphere/examples/ubuntu/ubuntu-16.04.pkr.hcl new file mode 100644 index 000000000..9901293b6 --- /dev/null +++ b/builder/vsphere/examples/ubuntu/ubuntu-16.04.pkr.hcl @@ -0,0 +1,52 @@ +# source blocks are analogous to the "builders" in json templates. They are used +# in build blocks. A build block runs provisioners and post-processors on a +# source. Read the documentation for source blocks here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/source +source "vsphere-iso" "example" { + CPUs = 1 + RAM = 1024 + RAM_reserve_all = true + boot_command = ["", + "", + "", + "", + "", + "", + "", + "", + "", + "", "/install/vmlinuz", + " initrd=/install/initrd.gz", " priority=critical", + " locale=en_US", " file=/media/preseed.cfg", + ""] + disk_controller_type = ["pvscsi"] + floppy_files = ["${path.root}/preseed.cfg"] + guest_os_type = "ubuntu64Guest" + host = "esxi-1.vsphere65.test" + insecure_connection = true + iso_paths = ["[datastore1] ISO/ubuntu-16.04.3-server-amd64.iso"] + network_adapters { + network_card = "vmxnet3" + } + password = "jetbrains" + ssh_password = "jetbrains" + ssh_username = "jetbrains" + storage { + disk_size = 32768 + disk_thin_provisioned = true + } + username = "root" + vcenter_server = "vcenter.vsphere65.test" + vm_name = "example-ubuntu" +} + +# a build block invokes sources and runs provisioning steps on them. The +# documentation for build blocks can be found here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/build +build { + sources = ["source.vsphere-iso.example"] + + provisioner "shell" { + inline = ["ls /"] + } +} diff --git a/builder/vsphere/examples/windows/windows-10.json b/builder/vsphere/examples/windows/windows-10.json index 5d494b46f..e9df38503 100644 --- a/builder/vsphere/examples/windows/windows-10.json +++ b/builder/vsphere/examples/windows/windows-10.json @@ -2,47 +2,47 @@ "builders": [ { "type": "vsphere-iso", - - "vcenter_server": "vcenter.vsphere65.test", - "username": "root", - "password": "jetbrains", - "insecure_connection": "true", - - "vm_name": "example-windows", - "host": "esxi-1.vsphere65.test", - - "guest_os_type": "windows9_64Guest", - - "communicator": "winrm", - "winrm_username": "jetbrains", - "winrm_password": "jetbrains", - - "CPUs": 1, - "RAM": 4096, + "CPUs": 1, + "RAM": 4096, "RAM_reserve_all": true, - - "disk_controller_type": "pvscsi", - "disk_size": 32768, - "disk_thin_provisioned": true, - - "network_card": "vmxnet3", - + "communicator": "winrm", + "disk_controller_type": "pvscsi", + "floppy_files": [ + "{{template_dir}}/setup/" + ], + "floppy_img_path": "[datastore1] ISO/VMware Tools/10.2.0/pvscsi-Windows8.flp", + "guest_os_type": "windows9_64Guest", + "host": "esxi-1.vsphere65.test", + "insecure_connection": "true", "iso_paths": [ "[datastore1] ISO/en_windows_10_multi-edition_vl_version_1709_updated_dec_2017_x64_dvd_100406172.iso", "[datastore1] ISO/VMware Tools/10.2.0/windows.iso" ], - - "floppy_files": [ - "{{template_dir}}/setup/" + "network_adapters": [ + { + "network_card": "vmxnet3" + } ], - "floppy_img_path": "[datastore1] ISO/VMware Tools/10.2.0/pvscsi-Windows8.flp" + "password": "jetbrains", + "storage": [ + { + "disk_size": 32768, + "disk_thin_provisioned": true + } + ], + "username": "root", + "vcenter_server": "vcenter.vsphere65.test", + "vm_name": "example-windows", + "winrm_password": "jetbrains", + "winrm_username": "jetbrains" } ], - "provisioners": [ { - "type": "windows-shell", - "inline": ["dir c:\\"] + "inline": [ + "dir c:\\" + ], + "type": "windows-shell" } ] -} +} \ No newline at end of file diff --git a/builder/vsphere/examples/windows/windows-10.pkr.hcl b/builder/vsphere/examples/windows/windows-10.pkr.hcl new file mode 100644 index 000000000..e2b2ad670 --- /dev/null +++ b/builder/vsphere/examples/windows/windows-10.pkr.hcl @@ -0,0 +1,41 @@ +# source blocks are generated from your builders; a source can be referenced in +# build blocks. A build block runs provisioner and post-processors on a +# source. Read the documentation for source blocks here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/source +source "vsphere-iso" "example_windows" { + CPUs = 1 + RAM = 4096 + RAM_reserve_all = true + communicator = "winrm" + disk_controller_type = ["pvscsi"] + floppy_files = ["${path.root}/setup/"] + floppy_img_path = "[datastore1] ISO/VMware Tools/10.2.0/pvscsi-Windows8.flp" + guest_os_type = "windows9_64Guest" + host = "esxi-1.vsphere65.test" + insecure_connection = "true" + iso_paths = ["[datastore1] ISO/en_windows_10_multi-edition_vl_version_1709_updated_dec_2017_x64_dvd_100406172.iso", "[datastore1] ISO/VMware Tools/10.2.0/windows.iso"] + network_adapters { + network_card = "vmxnet3" + } + password = "jetbrains" + storage { + disk_size = 32768 + disk_thin_provisioned = true + } + username = "root" + vcenter_server = "vcenter.vsphere65.test" + vm_name = "example-windows" + winrm_password = "jetbrains" + winrm_username = "jetbrains" +} + +# a build block invokes sources and runs provisioning steps on them. The +# documentation for build blocks can be found here: +# https://www.packer.io/docs/templates/hcl_templates/blocks/build +build { + sources = ["source.vsphere-iso.example_windows"] + + provisioner "windows-shell" { + inline = ["dir c:\\"] + } +}