2020-03-18 18:46:47 -04:00
---
modeline: |
vim: set ft=pandoc:
2020-04-02 19:39:47 -04:00
description: >
This VMware Packer builder uses the vSphere API to clone an existing vSphere
template and create a new virtual machine remotely.
2020-03-24 19:48:37 -04:00
page_title: VSphere Clone - Builders
2020-04-02 19:39:47 -04:00
sidebar_title: VSphere Clone
2020-03-18 18:46:47 -04:00
---
# VMWare Vsphere Clone Builder
Type: `vsphere-clone`
2021-02-05 16:49:28 -08:00
Artifact BuilderId: `jetbrains.vsphere`
2020-03-18 18:46:47 -04:00
This builder clones VMs from existing templates.
- VMware Player is not required.
2021-01-15 14:39:39 -05:00
- It uses the official vCenter API, and does not require ESXi host [modification](/docs/builders/vmware-iso.html#building-on-a-remote-vsphere-hypervisor)
2020-07-09 14:46:35 -07:00
- This builder is supported for vSphere version 6.5 and greater. Builds on lower
2020-12-04 16:00:53 -05:00
versions may work, but some configuration options may throw errors because they
do not exist in the older versions of the vSphere API.
2020-03-18 18:46:47 -04:00
## Examples
See complete Ubuntu, Windows, and macOS templates in the [examples folder](https://github.com/hashicorp/packer/tree/master/builder/vsphere/examples/).
## VSphere-Clone Configuration Reference
There are many configuration options available for this builder. In addition to
the items listed here, you will want to look at the general configuration
2020-06-02 11:48:11 -04:00
references for [Hardware](#hardware-configuration),
2020-03-18 18:46:47 -04:00
[Output](#output-configuration),
2020-06-24 11:14:30 +02:00
[Boot](#boot-configuration),
2020-03-18 18:46:47 -04:00
[Run](#run-configuration),
[Shutdown](#shutdown-configuration),
[Communicator](#communicator-configuration),
[Export](#export-configuration),
configuration references, which are
necessary for this build to succeed and can be found further down the page.
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/clone/Config-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Clone Configuration
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/clone/CloneConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
2020-11-20 11:51:53 +01:00
@include 'builder/vsphere/common/StorageConfig-not-required.mdx'
### Storage Configuration
When cloning a VM, the storage configuration can be used to add additional storage and disk controllers. The resulting VM
will contain the origin VM storage and disk controller plus the new configured ones.
@include 'builder/vsphere/common/DiskConfig.mdx'
@include 'builder/vsphere/common/DiskConfig-required.mdx'
#### Optional
@include 'builder/vsphere/common/DiskConfig-not-required.mdx'
2020-07-08 10:33:45 +02:00
### vApp Options Configuration
@include 'builder/vsphere/clone/vAppConfig-not-required.mdx'
Example of usage:
<Tabs>
<Tab heading="JSON">
```json
"vapp": {
"properties": {
"hostname": "{{ user `hostname`}}",
"user-data": "{{ env `USERDATA`}}"
}
}
```
A `user-data` field requires the content of a yaml file to be encoded with base64. This
can be done via environment variable:
`export USERDATA=$(gzip -c9 <userdata.yaml | { base64 -w0 2>/dev/null || base64; })`
</Tab>
<Tab heading="HCL2">
```hcl
vapp {
properties = {
hostname = var.hostname
user-data = base64encode(var.user_data)
}
}
```
</Tab>
</Tabs>
2020-03-18 18:46:47 -04:00
### Extra Configuration Parameters
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/common/ConfigParamsConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
2020-07-29 09:09:58 +02:00
### Customization
@include '/builder/vsphere/clone/CustomizeConfig.mdx'
@include 'builder/vsphere/clone/CustomizeConfig-not-required.mdx'
#### Network Interface Settings
@include 'builder/vsphere/clone/NetworkInterface-not-required.mdx'
#### Global Routing Settings
@include 'builder/vsphere/clone/GlobalRoutingSettings.mdx'
@include 'builder/vsphere/clone/GlobalRoutingSettings-not-required.mdx'
#### Global DNS Settings
@include 'builder/vsphere/clone/GlobalDnsSettings.mdx'
@include 'builder/vsphere/clone/GlobalDnsSettings-not-required.mdx'
#### Linux Customization Settings
@include 'builder/vsphere/clone/LinuxOptions-not-required.mdx'
#### Customization Example
<Tabs>
<Tab heading="JSON">
```json
"customize": {
"linux_options": {
"host_name": "packer-test",
"domain": "test.internal"
},
"network_interface": {
"ipv4_address": "10.0.0.10",
"ipv4_netmask": "24"
2020-11-25 10:48:10 +01:00
},
"ipv4_gateway": "10.0.0.1",
"dns_server_list": ["10.0.0.18"]
2020-07-29 09:09:58 +02:00
}
```
</Tab>
<Tab heading="HCL2">
```hcl
customize {
linux_options {
host_name = "packer-test"
domain = "test.internal"
}
network_interface {
ipv4_address = "10.0.0.10"
ipv4_netmask = "24"
}
2020-11-25 10:48:10 +01:00
ipv4_gateway = 10.0.0.1
dns_server_list = ["10.0.0.18"]
2020-07-29 09:09:58 +02:00
}
```
</Tab>
</Tabs>
2020-06-24 11:14:30 +02:00
### Boot configuration
2020-11-12 14:44:02 -08:00
@include 'packer-plugin-sdk/bootcommand/BootConfig.mdx'
2020-06-24 11:14:30 +02:00
#### Optional:
2020-11-12 14:44:02 -08:00
@include 'packer-plugin-sdk/bootcommand/BootConfig-not-required.mdx'
2020-06-24 11:14:30 +02:00
2020-07-07 13:57:51 -04:00
@include 'builder/vsphere/common/BootConfig-not-required.mdx'
2020-06-24 11:14:30 +02:00
### Http directory configuration
2020-11-17 17:18:45 -08:00
@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig.mdx'
2020-06-24 11:14:30 +02:00
#### Optional:
2020-11-17 17:18:45 -08:00
@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx'
2020-06-24 11:14:30 +02:00
2020-09-18 17:09:01 +02:00
### Floppy configuration
@include 'builder/vsphere/common/FloppyConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Connection Configuration
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/common/ConnectConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Hardware Configuration
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/common/HardwareConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Location Configuration
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/common/LocationConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Run Configuration
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/common/RunConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Shutdown Configuration
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/common/ShutdownConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Wait Configuration
2020-03-23 20:02:12 -04:00
@include 'builder/vsphere/common/WaitIpConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
2020-09-18 17:09:01 +02:00
### CDRom Configuration
2020-11-17 17:18:45 -08:00
@include 'packer-plugin-sdk/multistep/commonsteps/CDConfig.mdx'
2020-09-18 17:09:01 +02:00
#### Optional:
2020-11-17 17:07:02 -08:00
@include 'packer-plugin-sdk/multistep/commonsteps/CDConfig-not-required.mdx'
2020-09-18 17:09:01 +02:00
2020-09-22 11:32:25 +02:00
@include 'builder/vsphere/common/CDRomConfig-not-required.mdx'
2020-09-18 17:09:01 +02:00
2020-09-23 10:32:16 +02:00
@include 'builder/vsphere/common/RemoveCDRomConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Communicator configuration
#### Optional common fields:
2020-12-01 15:30:31 -08:00
@include 'packer-plugin-sdk/communicator/Config-not-required.mdx'
2020-03-18 18:46:47 -04:00
#### Optional SSH fields:
2020-12-01 15:30:31 -08:00
@include 'packer-plugin-sdk/communicator/SSH-not-required.mdx'
2020-03-18 18:46:47 -04:00
2020-12-01 15:30:31 -08:00
@include 'packer-plugin-sdk/communicator/SSHTemporaryKeyPair-not-required.mdx'
2020-07-08 10:33:45 +02:00
2020-12-01 15:30:31 -08:00
@include 'packer-plugin-sdk/communicator/SSH-Key-Pair-Name-not-required.mdx'
2020-07-08 10:33:45 +02:00
2020-12-01 15:30:31 -08:00
@include 'packer-plugin-sdk/communicator/SSH-Private-Key-File-not-required.mdx'
2020-07-08 10:33:45 +02:00
2020-12-01 15:30:31 -08:00
@include 'packer-plugin-sdk/communicator/SSH-Agent-Auth-not-required.mdx'
2020-07-08 10:33:45 +02:00
2020-07-13 06:33:16 -04:00
-> **NOTE:** Packer uses vApp Options to inject ssh public keys to the Virtual Machine.
The [temporary_key_pair_name](/docs/builders/vmware/vsphere-clone#temporary_key_pair_name) will only work
if the template being cloned contains the vApp property `public-keys`.
If using [ssh_private_key_file](/docs/builders/vmware/vsphere-clone#ssh_private_key_file), provide
the public key via [configuration_parameters](/docs/builders/vmware/vsphere-clone#configuration_parameters) or
[vApp Options Configuration](/docs/builders/vmware/vsphere-clone#vapp-options-configuration) whenever the `guestinto.userdata`
is available. See [VMware Guestinfo datasource](https://github.com/vmware/cloud-init-vmware-guestinfo) for more information
about the key.
2020-07-08 10:33:45 +02:00
2020-03-18 18:46:47 -04:00
#### Optional WinRM fields:
2020-12-01 15:30:31 -08:00
@include 'packer-plugin-sdk/communicator/WinRM-not-required.mdx'
2020-03-18 18:46:47 -04:00
### Export Configuration
2020-04-02 14:15:08 -04:00
@include 'builder/vsphere/common/ExportConfig.mdx'
2020-03-18 18:46:47 -04:00
2020-08-05 19:23:52 +02:00
#### Optional:
2020-03-18 18:46:47 -04:00
2020-04-02 14:15:08 -04:00
@include 'builder/vsphere/common/ExportConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
#### Output Configuration:
2020-04-02 14:15:08 -04:00
@include 'builder/vsphere/common/OutputConfig-not-required.mdx'
2020-03-18 18:46:47 -04:00
2020-07-10 11:01:10 +02:00
### Content Library Import Configuration
@include 'builder/vsphere/common/ContentLibraryDestinationConfig.mdx'
@include 'builder/vsphere/common/ContentLibraryDestinationConfig-not-required.mdx'
Minimal example of usage:
<Tabs>
<Tab heading="JSON">
```json
"content_library_destination" : {
"library": "Packer Library Test"
}
```
</Tab>
<Tab heading="HCL2">
```hcl
content_library_destination {
library = "Packer Library Test"
}
```
</Tab>
</Tabs>
2020-10-09 13:09:06 -07:00
## Working With Clusters And Hosts
2020-03-18 18:46:47 -04:00
#### Standalone Hosts
Only use the `host` option. Optionally specify a `resource_pool`:
2020-08-05 19:23:52 +02:00
<Tabs>
<Tab heading="JSON">
```json
2020-03-18 18:46:47 -04:00
"host": "esxi-1.vsphere65.test",
"resource_pool": "pool1",
```
2020-08-05 19:23:52 +02:00
</Tab>
<Tab heading="HCL2">
```hcl
host = "esxi-1.vsphere65.test"
resource_pool = "pool1"
```
</Tab>
</Tabs>
2020-03-18 18:46:47 -04:00
#### Clusters Without DRS
Use the `cluster` and `host`parameters:
2020-08-05 19:23:52 +02:00
<Tabs>
<Tab heading="JSON">
```json
2020-03-18 18:46:47 -04:00
"cluster": "cluster1",
"host": "esxi-2.vsphere65.test",
```
2020-08-05 19:23:52 +02:00
</Tab>
<Tab heading="HCL2">
```hcl
cluster = "cluster1"
host = "esxi-2.vsphere65.test"
```
</Tab>
</Tabs>
2020-03-18 18:46:47 -04:00
#### Clusters With DRS
Only use the `cluster` option. Optionally specify a `resource_pool`:
2020-08-05 19:23:52 +02:00
<Tabs>
<Tab heading="JSON">
```json
2020-03-18 18:46:47 -04:00
"cluster": "cluster2",
"resource_pool": "pool1",
```
2020-08-05 19:23:52 +02:00
</Tab>
<Tab heading="HCL2">
```hcl
cluster = "cluster2"
resource_pool = "pool1"
```
</Tab>
</Tabs>
2020-03-18 18:46:47 -04:00
## Required vSphere Permissions
- VM folder (this object and children):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Virtual machine -> Inventory
Virtual machine -> Configuration
Virtual machine -> Interaction
Virtual machine -> Snapshot management
Virtual machine -> Provisioning
```
Individual privileges are listed in https://github.com/jetbrains-infra/packer-builder-vsphere/issues/97#issuecomment-436063235.
- Resource pool, host, or cluster (this object):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Resource -> Assign virtual machine to resource pool
```
- Host in clusters without DRS (this object):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Read-only
```
- Datastore (this object):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Datastore -> Allocate space
Datastore -> Browse datastore
Datastore -> Low level file operations
```
- Network (this object):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Network -> Assign network
```
- Distributed switch (this object):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Read-only
```
For floppy image upload:
- Datacenter (this object):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Datastore -> Low level file operations
```
- Host (this object):
2020-03-27 14:22:33 -04:00
```text
2020-03-18 18:46:47 -04:00
Host -> Configuration -> System Management
```