Skip to content

Instantly share code, notes, and snippets.

@yankcrime
Created April 20, 2021 11:24
Show Gist options
  • Save yankcrime/9bec18cbf622c74cc3546747004b2c79 to your computer and use it in GitHub Desktop.
Save yankcrime/9bec18cbf622c74cc3546747004b2c79 to your computer and use it in GitHub Desktop.
Packer configuration for Ubuntu 20.04 on vSphere with cloud-init and guestinfo
d-i passwd/user-fullname string packerbuilt
d-i passwd/username string packerbuilt
d-i passwd/user-password password PackerBuilt!
d-i passwd/user-password-again password PackerBuilt!
d-i user-setup/allow-password-weak boolean true
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-basicfilesystems/no_swap boolean false
d-i partman-swapfile/size string 0
d-i partman-auto/expert_recipe string root :: 1000 50 -1 ext4 \
$primary{ } $bootable{ } method{ format } \
format{ } use_filesystem{ } filesystem{ ext4 } \
mountpoint{ / } \
.
d-i partman-auto/choose_recipe select root
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i passwd/root-login boolean true
d-i passwd/root-password password PackerBuilt!
d-i passwd/root-password-again password PackerBuilt!
d-i pkgsel/include string open-vm-tools openssh-server perl perl-modules-5.30 \
cloud-guest-utils curl cloud-init python3-pip
d-i grub-installer/only_debian boolean true
d-i preseed/late_command string \
echo 'packerbuilt ALL=(ALL) NOPASSWD: ALL' > /target/etc/sudoers.d/packerbuilt ; \
in-target chmod 440 /etc/sudoers.d/packerbuilt ;
d-i finish-install/reboot_in_progress note
# Apply any updates
#
apt-get update ; apt-get -y dist-upgrade
# Disable swap - recommended for Kubernetes
#
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# Add cloud-init-vmware-guestinfo
#
curl -sSL https://raw.githubusercontent.com/vmware/cloud-init-vmware-guestinfo/master/install.sh | sh -
# Enable guest customisation with cloud-init (https://kb.vmware.com/s/article/59557)
#
echo 'disable_vmware_customization: false' >> /etc/cloud/cloud.cfg
# Reset any existing cloud-init state
#
cloud-init clean -s -l
# Cleanup
#
apt-get -y autoremove
apt-get -y clean
truncate -s 0 /etc/machine-id
rm /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id
{
"builders": [
{
"CPUs": 2,
"RAM": 2048,
"RAM_reserve_all": true,
"boot_command": [
"<enter><wait><f6><wait><esc><wait>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs>",
"/install/vmlinuz",
" initrd=/install/initrd.gz",
" priority=critical",
" locale=en_US",
" file=/media/preseed.cfg",
"<enter>"
],
"boot_order": "disk,cdrom",
"cluster": "{{user `cluster`}}",
"convert_to_template": "true",
"datastore": "{{user `datastore`}}",
"disk_controller_type": "pvscsi",
"floppy_files": [
"./preseed.cfg"
],
"folder": "{{user `folder`}}",
"guest_os_type": "ubuntu64Guest",
"host": "{{user `host`}}",
"insecure_connection": "true",
"iso_checksum": "MD5:9d2b54506f8f9fdad6b72e45aff0f0de",
"iso_urls": "http://cdimage.ubuntu.com/ubuntu-legacy-server/releases/20.04/release/ubuntu-20.04-legacy-server-amd64.iso",
"network_adapters": [
{
"network": "{{user `network`}}",
"network_card": "vmxnet3"
}
],
"password": "{{user `password`}}",
"ssh_password": "{{user `ssh_password`}}",
"ssh_username": "{{user `ssh_username`}}",
"storage": [
{
"disk_size": 8192,
"disk_thin_provisioned": true
}
],
"type": "vsphere-iso",
"username": "{{user `username`}}",
"vcenter_server": "{{user `vcenter_server`}}",
"vm_name": "{{ user `template_name`}}"
}
],
"provisioners": [
{
"execute_command": "echo '{{user `ssh_password`}}' | sudo -S -E bash '{{.Path}}'",
"scripts": [
"script.sh"
],
"type": "shell"
}
]
}
{
"vcenter_server":"",
"username":"[email protected]",
"password":"",
"datastore":"",
"folder": "",
"host":"",
"cluster": "",
"network": "",
"ssh_username": "packerbuilt",
"ssh_password": "PackerBuilt!",
"template_name": "ubuntu_2004_cloudinit"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment