Public | Automated Build

Last pushed: 4 months ago
Short Description
Simple bash script using packer for auto provisioning virtual machines to a free VMWare ESXi server.
Full Description

Packer ESXi VM Provisioner


Simple bash script using packer for auto provisioning virtual machines to a free VMWare ESXi server.
This script has been tested with VMWare ESXi version 6. At the moment the following guest operating systems are supported:

  • Ubuntu 14.04 (ubuntu-trusty)


  • Connect to ESXi server via SSH
  • Upload operating system ISO to datastore
  • Create virtual machine with specified parameters
  • Power on virtual machine and executing unattended operating system installation
  • Customize virtual machine with bash, ansible, chef, puppet and many more
  • Power off virtual machine and cleanup resources
  • Power on virtual machine to work with


VM Network

  • The virtual machine relies on an existing DCHP server on the specified vm network

ESXi Host


  • Enable SSH access on ESXi Host:

Allow network communication for Packer

  • Download init script to local PC:

  • Copy init script to ESXi host via SSH

    scp root@esxi:/etc/rc.local.d/
  • Make init script executable on ESXi host

    ssh root@esxi chmod +x /etc/rc.local.d/
  • Execute init script on ESXi host once

    ssh root@esxi /etc/rc.local.d/

Packer Host

  • Install additional software packages:

    sudo apt-get install git sshpass
  • Download and install packer from the website:

    sudo unzip -d /usr/local/bin
    rm -f


Plain Linux

  • Checkout project from GitHub:

    git clone
  • Change to project directory:

    cd packer-esxi
  • Run packer-esxi command:

    ./packer-esxi --help
    Packer ESXi VM Provisioner
      ./packer-esxi [Options] <Args>
      --esxi-server         <server>        The ESXi server
      --esxi-username       <username>      The ESXi username
      --esxi-password       <password>      The ESXi password
      --esxi-datastore      <datastore>     The ESXi datastore
      --vm-name             <name>          The VM name
      --vm-cores            <cores>         The number of virtual CPU Cores of the VM
      --vm-ram-size         <ram>           The RAM size of the VM (in MB)
      --vm-disk-size        <disk>          The Disk size of the VM (in GB)
      --vm-network          <network>       The Network name of the VM
      --os-type             <os>            The type of the OS
      --os-proxy            <proxy>         The proxy of the OS
      --os-username         <username>      The username of the OS
      --os-password         <password>      The password of the OS
      --os-domain           <domain>        The network domain of the OS
      --os-keyboard-layout  <layout>        The keyboard layout of the OS
      --os-locale           <locale>        The locale of the OS
      --os-timezone         <timezone>      The timezone of the OS
      --os-docker           <boolean>       Install docker engine in the OS
      --help                                Print this help text
      ./packer-esxi --esxi-server \
         --esxi-username root \
         --esxi-password my-password \
         --esxi-datastore my-datastore \
         --vm-name my-vm \
         --vm-cores 1 \
         --vm-ram-size  512 \
         --vm-disk-size 10 \
         --vm-network "VM Network" \
         --os-type ubuntu-trusty \
         --os-proxy none | \
         --os-username my-username \
         --os-password my-password \
         --os-domain my.domain \
         --os-locale de_DE.UTF-8 \
         --os-keyboard-layout de \
         --os-timezone Europe/Berlin \
         --os-docker true


  • Run via docker command:
    docker run --rm -v $HOME/.packer:/root/.packer -it chrisipa/packer-esxi



  • You can easily integrate the docker container into a parameterized build:

  • Just execute a shell command with the following content:

    #!/bin/bash +x
    # specify image name
    # pull docker image from registry
    docker pull "$imageName"
    # execute docker run
    docker run --rm -v $HOME/.packer:/root/.packer -t "$imageName" \
    --esxi-server "$ESXI_SERVER" \
    --esxi-username "$ESXI_USERNAME" \
    --esxi-password "$ESXI_PASSWORD" \
    --esxi-datastore "$ESXI_DATASTORE" \
    --vm-name "$VM_NAME" \
    --vm-cores "$VM_CORES" \
    --vm-ram-size "$VM_RAM_SIZE" \
    --vm-disk-size "$VM_DISK_SIZE" \
    --vm-network "$VM_NETWORK" \
    --os-type "$OS_TYPE" \
    --os-proxy "$OS_PROXY" \
    --os-username "$OS_USERNAME" \
    --os-password "$OS_PASSWORD" \
    --os-domain "$OS_DOMAIN" \
    --os-locale "$OS_LOCALE" \
    --os-keyboard-layout "$OS_KEYBOARD_LAYOUT" \
    --os-timezone "$OS_TIMEZONE" \
    --os-docker "$OS_DOCKER"
Docker Pull Command
Source Repository