mirror of
https://github.com/hashicorp/packer.git
synced 2026-10-07 15:10:28 -04:00
4343ca292a1f0a6c41aeac94e54ff05a01ba377d
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
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
Required
-
vcenter_server- vCenter server hostname. -
username- vSphere username. -
password- vSphere password. -
insecure_connection- do not validate server's TLS certificate.falseby default. -
template- name of source VM. -
vm_name- name of target VM. -
host- vSphere host where target VM is created. -
ssh_username- username in guest OS. -
ssh_password- password in guest OS.
Optional
Destination:
datacenter- required if there are several datacenters.folder- VM folder where target VM is created.resource_pool- by default a root of vSphere host.datastore- required if vSphere host has multiple datastores attached.linked_clone- create VM as a linked clone from latest snapshot.falseby default.
Hardware customization:
CPUs- number of CPU sockets. Inherited from source VM by default.RAM- Amount of RAM in megabytes. Inherited from source VM by default.
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.falseby default.convert_to_template- convert VM to a template.falseby 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": "ubuntu",
"folder": "folder1/folder2",
"vm_name": "vm-1",
"host": "esxi-1.domain.com",
"resource_pool": "pool1/pool2",
"datastore": "datastore1",
"linked_clone": true,
"CPUs": 2,
"RAM": 8192,
"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"
]
}
]
}
Languages
Go
94.2%
HCL
4%
Shell
0.8%
Makefile
0.3%
MDX
0.3%
Other
0.4%