Go to file
Michael Kuzmin 4267014a5e
Merge pull request #42 from jetbrains-infra/driver_tests
Add acceptance tests for driver package
2018-01-23 22:34:41 +03:00
driver Merge pull request #42 from jetbrains-infra/driver_tests 2018-01-23 22:34:41 +03:00
.gitignore Separate configs for connection & cloning 2017-07-02 18:23:30 +03:00
LICENSE.txt Add Mozilla Public License 2.0 - the same as in Packer itself 2017-08-24 14:03:49 +03:00
README.md Add ability to control nested hardware virtualization 2018-01-16 15:24:44 +03:00
artifact.go Refactor vSphere driver 2017-08-24 17:54:08 +03:00
build.sh fix build script 2017-07-30 04:06:50 +03:00
builder.go 'communicator: none' can be used to clone and customize VMs without provisioning 2018-01-16 16:18:35 +03:00
builder_acc_test.go Add more acceptance tests for VM. Merge them into 1 table-driven test 2017-11-15 00:47:33 +03:00
builder_test.go Unit tests 2017-07-01 15:52:58 +03:00
config.go refactor ssh connection 2017-08-31 19:19:03 +03:00
config_test.go Code cleanup 2017-07-03 00:59:46 +03:00
docker-compose.yml Update build scripts 2017-07-30 03:56:10 +03:00
glide.lock Lock dependencies 2017-06-27 10:44:38 +03:00
glide.yaml Lock dependencies 2017-06-27 10:44:38 +03:00
main.go Builder (#2) 2017-05-09 17:23:57 +03:00
ssh.go refactor ssh connection 2017-08-31 19:19:03 +03:00
step_clone.go handle VM clone errors 2017-08-24 21:54:01 +03:00
step_connect.go Extract vSphere driver into separate package (#35) 2017-08-23 21:40:57 +02:00
step_hardware.go Add ability to control nested hardware virtualization 2018-01-16 15:24:44 +03:00
step_run.go Refactor vSphere driver 2017-08-24 17:54:08 +03:00
step_shutdown.go Refactor vSphere driver 2017-08-24 17:54:08 +03:00
step_snapshot.go Refactor vSphere driver 2017-08-24 17:54:08 +03:00
step_template.go Refactor vSphere driver 2017-08-24 17:54:08 +03:00
test-key.pem refactor ssh connection 2017-08-31 19:19:03 +03:00
test-key.pub refactor ssh connection 2017-08-31 19:19:03 +03:00
test.sh Add some acceptance tests for `VirtualMachine` and `Datastore` 2017-10-25 23:20:59 +03:00

README.md

Packer Builder for VMware vSphere

This a plugin for HashiCorp Packer. It uses native vSphere API, and creates virtual machines remotely.

  • VMware Player is not required
  • Builds are incremental, VMs are not created from scratch but cloned from base templates - similar to amazon-ebs builder
  • Official vCenter API is used, no ESXi host modification is required

Usage

  • Download the plugin from Releases page.
  • Install the plugin, or simply put it into the same directory with configuration files. On Linux and macOS run chmod +x on the plugin binary.

Minimal Example

{
  "builders": [
    {
      "type": "vsphere",

      "vcenter_server": "vcenter.domain.com",
      "username": "root",
      "password": "secret",

      "template": "ubuntu",
      "vm_name":  "vm-1",
      "host":     "esxi-1.domain.com",

      "ssh_username": "root",
      "ssh_password": "secret"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "inline": [ "echo hello" ]
    }
  ]
}

Parameters

Connection:

  • vcenter_server - [mandatory] vCenter server hostname.
  • username - [mandatory] vSphere username.
  • password - [mandatory] vSphere password.
  • insecure_connection - do not validate server's TLS certificate. false by default.
  • datacenter - required if there are several datacenters.

Location:

  • template - [mandatory] name of source VM. Path is optional.
  • vm_name - [mandatory] name of target VM.
  • folder - VM folder where target VM is created.
  • host - [mandatory] vSphere host or cluster where target VM is created. If hosts are groupped into folders, full path should be specified: folder/host.
  • resource_pool - by default a root of vSphere host.
  • datastore - required if target is a cluster, or a host with multiple datastores.
  • linked_clone - create VM as a linked clone from latest snapshot. false by default.

Hardware customization:

  • CPUs - number of CPU sockets. Inherited from source VM by default.
  • CPU_reservation - Amount of reserved CPU resources in MHz. Inherited from source VM by default.
  • CPU_limit - Upper limit of available CPU resources in MHz. Inherited from source VM by default, set to -1 for reset.
  • RAM - Amount of RAM in megabytes. Inherited from source VM by default.
  • RAM_reservation - Amount of reserved RAM in MB. Inherited from source VM by default.
  • RAM_reserve_all - Reserve all available RAM (bool). false by default. Cannot be used together with RAM_reservation.
  • disk_size - Change the disk size (in GB). VM should have a single disk. Cannot be used together with linked_clone.
  • NestedHV - Allows to enable nested hardware virtualization for VM.

Provisioning:

  • ssh_username - [mandatory] username in guest OS.
  • ssh_password or ssh_private_key_file - [mandatory] password or SSH-key filename to access a guest OS.

Post-processing:

  • shutdown_command - VMware guest tools are used by default.
  • shutdown_timeout - Duration how long to wait for a graceful shutdown. 5 minutes by default.
  • create_snapshot - add a snapshot, so VM can be used as a base for linked clones. false by default.
  • convert_to_template - convert VM to a template. false by default.

Complete Example

{
  "variables": {
    "vsphere_password": "secret",
    "guest_password": "secret"
  },

  "builders": [
    {
      "type": "vsphere",

      "vcenter_server": "vcenter.domain.com",
      "username": "root",
      "password": "{{user `vsphere_password`}}",
      "insecure_connection": true,
      "datacenter": "dc1",

      "template": "folder/ubuntu",
      "vm_name": "vm-1",
      "folder": "folder1/folder2",
      "host": "folder/esxi-1.domain.com",
      "resource_pool": "pool1/pool2",
      "datastore": "datastore1",
      "linked_clone": true,

      "CPUs": 2,
      "CPU_reservation": 1000,
      "CPU_limit": 2000,
      "RAM": 8192,
      "RAM_reservation": 2048,

      "ssh_username": "root",
      "ssh_password": "{{user `guest_password`}}",

      "shutdown_command": "echo '{{user `guest_password`}}' | sudo -S shutdown -P now",
      "shutdown_timeout": "5m",
      "create_snapshot": true,
      "convert_to_template": true
    }
  ],

  "provisioners": [
    {
      "type": "shell",
      "environment_vars": [
        "DEBIAN_FRONTEND=noninteractive"
      ],
      "execute_command": "echo '{{user `guest_password`}}' | {{.Vars}} sudo -ES bash -eux '{{.Path}}'",
      "inline": [
        "apt-get install -y zip"
      ]
    }
  ]
}