Skip to content

Instantly share code, notes, and snippets.

@gogson
Last active December 7, 2020 22:02
Show Gist options
  • Select an option

  • Save gogson/ce7069d003c1b83286e111f7c0ed22bb to your computer and use it in GitHub Desktop.

Select an option

Save gogson/ce7069d003c1b83286e111f7c0ed22bb to your computer and use it in GitHub Desktop.

Revisions

  1. gogson revised this gist May 9, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions packer-esxi-static-network.json
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,7 @@
    "initrd=/install/initrd.gz ",
    "<enter>"
    ],
    "keep_registered": true,
    "boot_wait": "10s",
    "disk_size": 40000,
    "headless": true,
  2. gogson revised this gist May 2, 2016. No changes.
  3. gogson revised this gist May 2, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion packer-esxi-static-network.json
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    {
    "vm_name": "my-vm",
    "keep_registered": "true",
    "remote_type": "esx5",
    "remote_host": "exsi.myhost.com",
    "remote_password": "myEsxiRootPassword",
  4. gogson revised this gist May 2, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions packer-esxi-static-network.json
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    {
    "vm_name": "my-vm",
    "keep_registered": "true",
    "remote_type": "esx5",
    "remote_host": "exsi.myhost.com",
    "remote_password": "myEsxiRootPassword",
  5. gogson revised this gist May 2, 2016. No changes.
  6. gogson renamed this gist May 2, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. gogson created this gist May 2, 2016.
    64 changes: 64 additions & 0 deletions packer-template.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    {
    "vm_name": "my-vm",
    "remote_type": "esx5",
    "remote_host": "exsi.myhost.com",
    "remote_password": "myEsxiRootPassword",
    "remote_datastore": "datastore1",
    "type": "vmware-iso",
    "output_directory": "output-vm",
    "floppy_files": [
    "preseed.cfg",
    ],
    "boot_command": [
    "<enter><wait>",
    "<f6><esc>",
    "<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 ",
    "preseed/file=/floppy/preseed.cfg ",
    "net.ifnames=0 ",
    "auto-install/enable=true ",
    "hostname={{user `hostname`}} ",
    "nwhwconf=device:eth0,hwaddr:00:50:56:01:a2:30 ",
    "debconf/priority=critical ",
    "debconf/frontend=noninteractive ",
    "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=ssh_username keyboard-configuration/variant=USA console-setup/ask_detect=false ",
    "initrd=/install/initrd.gz ",
    "<enter>"
    ],
    "boot_wait": "10s",
    "disk_size": 40000,
    "headless": true,
    "guest_os_type": "ubuntu-64",
    "http_directory": "http",
    "iso_checksum": "e83adb9af4ec0a039e6a5c6e145a34de",
    "iso_checksum_type": "md5",
    "iso_url": "resources/ubuntu-12.04.4-server-amd64.iso",
    "ssh_username": "vagrant",
    "ssh_password": "vagrant",
    "ssh_port": 22,
    "ssh_skip_request_pty": true,
    "ssh_wait_timeout": "10000s",
    "shutdown_command": "echo 'shutdown -P now' > shutdown.sh; echo 'vagrant'| sudo -S sh 'shutdown.sh'",
    "tools_upload_flavor": "linux",
    "vmx_data": {
    "memsize": "4096",
    "numvcpus": "4",
    "cpuid.coresPerSocket": "2",
    "ethernet0.present": "TRUE",
    "ethernet0.startConnected": "TRUE",
    "ethernet0.virtualDev": "e1000",
    "ethernet0.networkName": "VM Network",
    "ethernet0.addressType": "static",
    "ethernet0.address": "00:50:56:01:a2:30",
    "ethernet0.connectionType": "bridged",
    "ethernet0.wakeOnPcktRcv": "FALSE"
    }
    }
    33 changes: 33 additions & 0 deletions preseed.cfg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    ### We use late_command to create the final /etc/network/interfaces file
    ### containing the static configuration of the VM's network.
    ### We write the file in the /target partition using the late_command.
    ### This partition is used during installation.
    ### Once system is installed and rebooted, we overwrite the current interfaces file
    ### and restart network. Packer can now SSH into the VM and finish provisioning.
    ###
    ### Notes:
    ### - You will need to provision your VM's virtual MAC address in the packer template. (mine is 00:50:56:01:a2:30)
    ### - I won't explain the interface configuration itself as it depends on your ESXi provider (mine is OVH)

    # Configure and setup network interface files
    d-i preseed/late_command string \
    echo 'auto lo eth0' > /target/etc/network/target-interfaces; \
    echo 'iface lo inet loopback' >> /target/etc/network/target-interfaces; \
    echo 'iface eth0 inet static' >> /target/etc/network/target-interfaces; \
    echo 'address 164.132.15.42' >> /target/etc/network/target-interfaces; \
    echo 'netmask 255.255.255.255' >> /target/etc/network/target-interfaces; \
    echo 'broadcast 164.132.15.42' >> /target/etc/network/target-interfaces; \
    echo 'post-up route add 42.255.68.254 dev eth0' >> /target/etc/network/target-interfaces; \
    echo 'post-up route add default gw 42.255.68.254' >> /target/etc/network/target-interfaces; \
    echo 'pre-down route del 42.255.68.254 dev eth0' >> /target/etc/network/target-interfaces; \
    echo 'pre-down route del default gw 42.255.68.254' >> /target/etc/network/target-interfaces; \
    echo 'dns-nameservers 213.186.33.99 8.8.8.8 4.4.4.4' >> /target/etc/network/target-interfaces; \
    echo 'dns-search ovh.net' >> /target/etc/network/target-interfaces; \
    in-target cp /etc/network/target-interfaces /etc/network/interfaces; \
    in-target service networking restart

    # Disable automatic network during system installation
    d-i netcfg/disable_autoconfig boolean true
    d-i netcfg/use_autoconfig boolean false
    d-i netcfg/confirm_static boolean true
    d-i netcfg/enable boolean false