Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Created December 3, 2019 18:08
Show Gist options
  • Save mrlesmithjr/7c91332a4967e1bf284c2e2483dd3050 to your computer and use it in GitHub Desktop.
Save mrlesmithjr/7c91332a4967e1bf284c2e2483dd3050 to your computer and use it in GitHub Desktop.
Packer Nested ESXi Builds
#Accept the VMware End User License Agreement
vmaccepteula
# clear paritions and install
clearpart --firstdisk --overwritevmfs
install --firstdisk --overwritevmfs --novmfsondisk
#set the root password
rootpw VMw@re1
#Host Network Settings
network --bootproto=dhcp --device=vmnic0
reboot
#Firstboot section 1
%firstboot --interpreter=busybox
sleep 30
#Enter Maintenance mode
vim-cmd hostsvc/maintenance_mode_enter
#enable & start remote ESXi Shell (SSH)
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh
#enable & start ESXi Shell (TSM)
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell
#suppress Shell Warning
esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1
esxcli system settings advanced set -o /UserVars/ESXiShellTimeOut -i 1
#Firstboot Section 2
%firstboot --interpreter=busybox
#Disable IPv6
esxcli network ip set --ipv6-enabled=false
#Disable CEIP
esxcli system settings advanced set -o /UserVars/HostClientCEIPOptIn -i 2
# Exit Maintenance Mode
vim-cmd hostsvc/maintenance_mode_exit
#Reboot
sleep 30
reboot
{
"variables": {
"vm_name": "esxi67_x64",
"iso_url": "/Users/larrysmithjr/projects/devops_automation/mounts/Images/ISOs/esxi67_x64.iso",
"save_to_filename": "/Users/larrysmithjr/projects/devops_automation/mounts/Images/Base_Images/esxi67_x64",
"disk_size": "8192",
"guest_os_type": "vmkernel65",
"iso_checksum": "884ead30532f4a5c2152e4ac450839a0062aba3ae859b5fa5e233ce4275c8cb6",
"vcpu": "2",
"ssh_username": "root",
"disk_adapter_type": "scsi",
"remove_interfaces": "True",
"http_directory": "http",
"iso_checksum_type": "sha256",
"headless": "True",
"version": "10",
"shutdown_command": "esxcli system maintenanceMode set -e true -t 0; esxcli system shutdown poweroff -d 10 -r \"Packer Shutdown\"; esxcli system maintenanceMode set -e false -t 0",
"ssh_password": "VMw@re1",
"memory": "4096",
"save_to_dir": "/Users/larrysmithjr/projects/devops_automation/mounts/Images/Base_Images",
"output_directory": "/Users/larrysmithjr/projects/devops_automation/image_builder/output-vmware-iso",
"vmx_file": "/Users/larrysmithjr/projects/devops_automation/image_builder/output-vmware-iso/esxi67_x64.vmx"
},
"provisioners": [
{
"inline": [
"esxcli system settings advanced set -o /Net/FollowHardwareMac -i 1",
"sed -i '/\\/system\\/uuid/d' /etc/vmware/esx.conf",
"sed -i '/\\/net\\/pnic\\/child\\[0000\\]\\/mac/d' /etc/vmware/esx.conf",
"sed -i '/\\/net\\/vmkernelnic\\/child\\[0000\\]\\/mac/d' /etc/vmware/esx.conf",
"/sbin/auto-backup.sh"
],
"type": "shell"
}
],
"builders": [
{
"iso_url": "{{ user `iso_url` }}",
"cpus": "{{ user `vcpu` }}",
"iso_checksum_type": "{{ user `iso_checksum_type` }}",
"disk_type_id": 0,
"iso_checksum": "{{ user `iso_checksum` }}",
"memory": "{{ user `memory` }}",
"ssh_wait_timeout": "60m",
"type": "vmware-iso",
"vm_name": "{{ user `vm_name` }}",
"pause_before_connecting": "10m",
"ssh_username": "{{ user `ssh_username` }}",
"disk_adapter_type": "{{ user `disk_adapter_type` }}",
"vmx_remove_ethernet_interfaces": "{{ user `remove_interfaces` }}",
"shutdown_command": "{{ user `shutdown_command` }}",
"boot_command": [
"<enter><wait>O<wait> ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter>"
],
"output_directory": "{{ user `output_directory` }}",
"disk_size": "{{ user `disk_size` }}",
"guest_os_type": "{{ user `guest_os_type` }}",
"http_directory": "{{ user `http_directory` }}",
"vmx_data": {
"vhv.enable": "TRUE"
},
"headless": "{{ user `headless` }}",
"ssh_password": "{{ user `ssh_password` }}"
}
],
"post-processors": [
{
"inline": "ovftool {{ user `vmx_file` }} {{ user `save_to_filename` }}.ova",
"type": "shell-local"
},
{
"inline": "ovftool {{ user `vmx_file` }} {{ user `save_to_filename` }}.ovf",
"type": "shell-local"
},
{
"output": "{{ user `save_to_dir` }}/packer-manifest.json",
"type": "manifest",
"strip_path": true
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment