├── LICENSE ├── README.md ├── debian-9-base.json ├── preseed ├── debian.cfg └── ubuntu.cfg ├── scripts └── open-vm-tools.sh ├── ubuntu-1404-base.json ├── ubuntu-1604-base.json └── variables.json /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Nick Charlton 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # packer-esxi 2 | 3 | A set of example [Packer][] templates for building Debian and Ubuntu boxes on 4 | [VMware ESXi][]. These are built on the remote ESXi host, then shut down and 5 | left registered. A lot of this work comes out of [boxes][], which provides the 6 | basic template formation. 7 | 8 | They assume that it's possible to fetch an IP through DHCP on the primary (`VM 9 | Network`) network. If this isn't the case, you can adjust the [boot command to 10 | set a static IP][]. 11 | 12 | This example repo comes out of [this post I wrote on how to use Packer with 13 | VMware ESXi][post]. 14 | 15 | ## Usage 16 | 17 | ```sh 18 | packer build -var-file variables.json ubuntu-1604-base.json 19 | ``` 20 | 21 | Ensure that `variables.json` contains valid values. 22 | 23 | ## Author 24 | 25 | Copyright (c) 2016 Nick Charlton. MIT Licensed. 26 | 27 | [Packer]: https://packer.io 28 | [VMware ESXi]: http://www.vmware.com/products/vsphere-hypervisor.html 29 | [boxes]: https://github.com/nickcharlton/boxes 30 | [boot command to set a static IP]: https://help.ubuntu.com/lts/installation-guide/armhf/apbs02.html 31 | [post]: https://nickcharlton.net/posts/using-packer-esxi-6.html 32 | -------------------------------------------------------------------------------- /debian-9-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "builders": [{ 3 | "name": "debian-9-base", 4 | "vm_name": "debian-9-base", 5 | "type": "vmware-iso", 6 | "guest_os_type": "debian9-64", 7 | "output_directory": "debian-9-base", 8 | "tools_upload_flavor": "linux", 9 | "headless": true, 10 | 11 | "iso_url": "http://debian.ethz.ch/debian-cd/9.9.0/amd64/iso-cd/debian-9.9.0-amd64-netinst.iso", 12 | "iso_checksum": "d4a22c81c76a66558fb92e690ef70a5d67c685a08216701b15746586520f6e8e", 13 | "iso_checksum_type": "sha256", 14 | 15 | "ssh_username": "nullgrid", 16 | "ssh_password": "nullgrid", 17 | "ssh_timeout": "15m", 18 | 19 | "disk_type_id": "thin", 20 | 21 | "boot_command": [ 22 | "", 23 | "install ", 24 | "preseed/url=http://nullgrid.s3.amazonaws.com/debian.cfg ", 25 | "debian-installer=en_US auto=true locale=en_US kbd-chooser/method=us ", 26 | "netcfg/get_hostname={{ .Name }} ", 27 | "netcfg/get_domain=nullgrid.net ", 28 | "fb=false debconf/frontend=noninteractive ", 29 | "console-setup/ask_detect=false console-keymaps-at/keymap=us ", 30 | "keyboard-configuration/xkb-keymap=us ", 31 | "" 32 | ], 33 | 34 | "shutdown_command": "echo 'shutdown -h now' > shutdown.sh; echo 'nullgrid'|sudo -S sh 'shutdown.sh'", 35 | 36 | "remote_type": "esx5", 37 | "remote_host": "{{user `esxi_host`}}", 38 | "remote_datastore": "{{user `esxi_datastore`}}", 39 | "remote_username": "{{user `esxi_username`}}", 40 | "remote_password": "{{user `esxi_password`}}", 41 | "keep_registered": true, 42 | "vnc_disable_password": true, 43 | 44 | "vmx_data": { 45 | "ethernet0.networkName": "VM Network" 46 | } 47 | }], 48 | 49 | "provisioners": [ 50 | { 51 | "type": "shell", 52 | "scripts": [ 53 | "scripts/open-vm-tools.sh" 54 | ], 55 | 56 | "execute_command": "echo 'nullgrid' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" 57 | } 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /preseed/debian.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Based upon: https://help.ubuntu.com/12.04/installation-guide/example-preseed.txt 3 | # 4 | 5 | # localisation 6 | d-i debian-installer/locale string en_US.utf8 7 | d-i console-keymaps-at/keymap select us 8 | 9 | # networking 10 | d-i netcfg/choose_interface select auto 11 | d-i netcfg/get_hostname string unassigned-hostname 12 | d-i netcfg/get_domain string unassigned-domain 13 | d-i netcfg/wireless_wep string 14 | 15 | # apt mirrors 16 | d-i mirror/country string manual 17 | d-i mirror/http/hostname string http.us.debian.org 18 | d-i mirror/http/directory string /debian 19 | d-i mirror/http/proxy string 20 | 21 | # clock and time zone 22 | d-i clock-setup/utc boolean true 23 | d-i time/zone string GMT 24 | d-i clock-setup/ntp boolean true 25 | 26 | # partitioning 27 | d-i partman-auto/method string lvm 28 | d-i partman-lvm/device_remove_lvm boolean true 29 | d-i partman-md/device_remove_md boolean true 30 | d-i partman-lvm/confirm boolean true 31 | d-i partman-lvm/confirm_nooverwrite boolean true 32 | 33 | #d-i partman-auto-lvm/guided_size string max 34 | d-i partman-auto/choose_recipe select atomic 35 | d-i partman-partitioning/confirm_write_new_label boolean true 36 | d-i partman/choose_partition select finish 37 | d-i partman/confirm boolean true 38 | d-i partman/confirm_nooverwrite boolean true 39 | 40 | # users 41 | d-i passwd/root-login boolean false 42 | d-i passwd/user-fullname string Null Grid 43 | d-i passwd/username string nullgrid 44 | d-i passwd/user-password password nullgrid 45 | d-i passwd/user-password-again password nullgrid 46 | d-i user-setup/allow-password-weak boolean true 47 | d-i user-setup/encrypt-home boolean false 48 | 49 | # packages 50 | tasksel tasksel/first multiselect standard 51 | d-i pkgsel/include string openssh-server nfs-common curl ntp acpid sudo bzip2 \ 52 | rsync git ca-certificates net-tools 53 | d-i pkgsel/upgrade select full-upgrade 54 | d-i pkgsel/update-policy select none 55 | d-i popularity-contest/participate boolean false 56 | d-i preseed/late_command string sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list 57 | apt-cdrom-setup apt-setup/cdrom/set-first boolean false 58 | apt-mirror-setup apt-setup/use_mirror boolean true 59 | postfix postfix/main_mailer_type select No configuration 60 | 61 | # boot loader 62 | d-i grub-installer/bootdev string default 63 | d-i grub-installer/only_debian boolean true 64 | 65 | # hide the shutdown notice 66 | d-i finish-install/reboot_in_progress note 67 | -------------------------------------------------------------------------------- /preseed/ubuntu.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Based upon: https://help.ubuntu.com/12.04/installation-guide/example-preseed.txt 3 | # 4 | 5 | # localisation 6 | d-i debian-installer/locale string en_US.utf8 7 | d-i console-setup/ask_detect boolean false 8 | d-i keyboard-configuration/layoutcode string us 9 | 10 | # networking 11 | d-i netcfg/choose_interface select auto 12 | d-i netcfg/get_hostname string unassigned-hostname 13 | d-i netcfg/get_domain string unassigned-domain 14 | d-i netcfg/wireless_wep string 15 | 16 | # apt mirrors 17 | d-i mirror/country string manual 18 | d-i mirror/http/hostname string archive.ubuntu.com 19 | d-i mirror/http/directory string /ubuntu 20 | d-i mirror/http/proxy string 21 | 22 | # clock and time zone 23 | d-i clock-setup/utc boolean true 24 | d-i time/zone string GMT 25 | d-i clock-setup/ntp boolean true 26 | 27 | # partitioning 28 | d-i partman-auto/method string lvm 29 | d-i partman-lvm/device_remove_lvm boolean true 30 | d-i partman-md/device_remove_md boolean true 31 | d-i partman-lvm/confirm boolean true 32 | # fix: http://serverfault.com/questions/189328/ubuntu-kickstart-installation-using-lvm-waits-for-input 33 | d-i partman-lvm/confirm_nooverwrite boolean true 34 | d-i partman-auto-lvm/guided_size string max 35 | d-i partman-auto/choose_recipe select atomic 36 | d-i partman-partitioning/confirm_write_new_label boolean true 37 | d-i partman/choose_partition select finish 38 | d-i partman/confirm boolean true 39 | d-i partman/confirm_nooverwrite boolean true 40 | 41 | # users 42 | d-i passwd/user-fullname string Null Grid 43 | d-i passwd/username string nullgrid 44 | d-i passwd/user-password password nullgrid 45 | d-i passwd/user-password-again password nullgrid 46 | d-i user-setup/allow-password-weak boolean true 47 | d-i user-setup/encrypt-home boolean false 48 | 49 | # packages 50 | tasksel tasksel/first multiselect standard, ubuntu-server 51 | d-i pkgsel/install-language-support boolean false 52 | d-i pkgsel/include string openssh-server nfs-common curl git-core 53 | d-i pkgsel/upgrade select full-upgrade 54 | d-i pkgsel/update-policy select none 55 | postfix postfix/main_mailer_type select No configuration 56 | 57 | # boot loader 58 | d-i grub-installer/only_debian boolean true 59 | 60 | # hide the shutdown notice 61 | d-i finish-install/reboot_in_progress note 62 | -------------------------------------------------------------------------------- /scripts/open-vm-tools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | apt-get install -qy open-vm-tools 4 | -------------------------------------------------------------------------------- /ubuntu-1404-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "builders": [{ 3 | "name": "ubuntu-1404-base", 4 | "vm_name": "ubuntu-1404-base", 5 | "type": "vmware-iso", 6 | "guest_os_type": "ubuntu-64", 7 | "tools_upload_flavor": "linux", 8 | "headless": false, 9 | 10 | "iso_url": "http://old-releases.ubuntu.com/releases/trusty/ubuntu-14.04.5-server-amd64.iso", 11 | "iso_checksum": "dde07d37647a1d2d9247e33f14e91acb10445a97578384896b4e1d985f754cc1", 12 | "iso_checksum_type": "sha256", 13 | 14 | "ssh_username": "nullgrid", 15 | "ssh_password": "nullgrid", 16 | "ssh_timeout": "15m", 17 | 18 | "disk_type_id": "thin", 19 | 20 | "floppy_files": [ 21 | "preseed/ubuntu.cfg" 22 | ], 23 | 24 | "boot_command": [ 25 | "", 26 | "/install/vmlinuz noapic ", 27 | "preseed/file=/floppy/ubuntu.cfg ", 28 | "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", 29 | "hostname={{ .Name }} ", 30 | "fb=false debconf/frontend=noninteractive ", 31 | "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", 32 | "keyboard-configuration/variant=USA console-setup/ask_detect=false ", 33 | "initrd=/install/initrd.gz -- " 34 | ], 35 | 36 | "shutdown_command": "echo 'shutdown -P now' > shutdown.sh; echo 'nullgrid'|sudo -S sh 'shutdown.sh'", 37 | 38 | "remote_type": "esx5", 39 | "remote_host": "{{user `esxi_host`}}", 40 | "remote_datastore": "{{user `esxi_datastore`}}", 41 | "remote_username": "{{user `esxi_username`}}", 42 | "remote_password": "{{user `esxi_password`}}", 43 | "keep_registered": true, 44 | 45 | "vmx_data": { 46 | "ethernet0.networkName": "VM Network" 47 | } 48 | }], 49 | 50 | "provisioners": [ 51 | { 52 | "type": "shell", 53 | "scripts": [ 54 | "scripts/open-vm-tools.sh" 55 | ], 56 | 57 | "execute_command": "echo 'nullgrid' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" 58 | } 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /ubuntu-1604-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "builders": [{ 3 | "name": "ubuntu-1604-base", 4 | "vm_name": "ubuntu-1604-base", 5 | "type": "vmware-iso", 6 | "guest_os_type": "ubuntu-64", 7 | "tools_upload_flavor": "linux", 8 | "headless": false, 9 | 10 | "iso_url": "http://old-releases.ubuntu.com/releases/xenial/ubuntu-16.04.2-server-amd64.iso", 11 | "iso_checksum": "737ae7041212c628de5751d15c3016058b0e833fdc32e7420209b76ca3d0a535", 12 | "iso_checksum_type": "sha256", 13 | 14 | "ssh_username": "nullgrid", 15 | "ssh_password": "nullgrid", 16 | "ssh_timeout": "15m", 17 | 18 | "disk_type_id": "thin", 19 | 20 | "floppy_files": [ 21 | "preseed/ubuntu.cfg" 22 | ], 23 | 24 | "boot_command": [ 25 | "", 26 | "", 27 | "", 28 | "", 29 | "/install/vmlinuz noapic ", 30 | "preseed/file=/floppy/ubuntu.cfg ", 31 | "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", 32 | "hostname={{ .Name }} ", 33 | "fb=false debconf/frontend=noninteractive ", 34 | "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", 35 | "keyboard-configuration/variant=USA console-setup/ask_detect=false ", 36 | "grub-installer/bootdev=/dev/sda ", 37 | "initrd=/install/initrd.gz -- " 38 | ], 39 | 40 | "shutdown_command": "echo 'shutdown -P now' > shutdown.sh; echo 'nullgrid'|sudo -S sh 'shutdown.sh'", 41 | 42 | "remote_type": "esx5", 43 | "remote_host": "{{user `esxi_host`}}", 44 | "remote_datastore": "{{user `esxi_datastore`}}", 45 | "remote_username": "{{user `esxi_username`}}", 46 | "remote_password": "{{user `esxi_password`}}", 47 | "keep_registered": true, 48 | 49 | "vmx_data": { 50 | "ethernet0.networkName": "VM Network" 51 | } 52 | }], 53 | 54 | "provisioners": [ 55 | { 56 | "type": "shell", 57 | "scripts": [ 58 | "scripts/open-vm-tools.sh" 59 | ], 60 | 61 | "execute_command": "echo 'nullgrid' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" 62 | } 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /variables.json: -------------------------------------------------------------------------------- 1 | { 2 | "esxi_host": "", 3 | "esxi_datastore": "primary", 4 | "esxi_username": "", 5 | "esxi_password": "" 6 | } 7 | --------------------------------------------------------------------------------