2018-04-25 07:47:42 -04:00
[![Team project ](http://jb.gg/badges/team.svg )](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
[![Github All Releases ](https://img.shields.io/github/downloads/jetbrains-infra/packer-builder-vsphere/total.svg )](https://github.com/jetbrains-infra/packer-builder-vsphere/releases)
[![TeamCity build status ](https://img.shields.io/teamcity/http/teamcity.jetbrains.com/s/PackerVSphere_Build.svg )](https://teamcity.jetbrains.com/viewType.html?buildTypeId=PackerVSphere_Build& guest=1)
2017-06-27 05:07:10 -04:00
# Packer Builder for VMware vSphere
2017-07-01 12:16:22 -04:00
This a plugin for [HashiCorp Packer ](https://www.packer.io/ ). It uses native vSphere API, and creates virtual machines remotely.
2017-06-27 05:07:10 -04:00
- VMware Player is not required
- Builds are incremental, VMs are not created from scratch but cloned from base templates - similar to [amazon-ebs ](https://www.packer.io/docs/builders/amazon-ebs.html ) builder
- Official vCenter API is used, no ESXi host [modification ](https://www.packer.io/docs/builders/vmware-iso.html#building-on-a-remote-vsphere-hypervisor ) is required
2017-05-14 18:15:24 -04:00
2017-06-23 19:19:44 -04:00
## Usage
2017-11-06 09:40:44 -05:00
* Download the plugin from [Releases ](https://github.com/jetbrains-infra/packer-builder-vsphere/releases ) page.
* [Install ](https://www.packer.io/docs/extending/plugins.html#installing-plugins ) the plugin, or simply put it into the same directory with configuration files. On Linux and macOS run `chmod +x` on the plugin binary.
2017-06-23 19:19:44 -04:00
2017-06-27 05:07:10 -04:00
## Minimal Example
```json
2017-06-09 18:44:24 -04:00
{
2017-06-27 05:07:10 -04:00
"builders": [
{
"type": "vsphere",
2017-07-01 11:54:10 -04:00
"vcenter_server": "vcenter.domain.com",
2017-06-27 05:07:10 -04:00
"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" ]
}
]
2017-06-09 18:44:24 -04:00
}
```
2017-05-31 05:49:28 -04:00
2017-06-27 05:07:10 -04:00
## Parameters
2017-07-01 12:16:22 -04:00
2017-07-01 12:27:09 -04:00
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.
2017-06-27 05:07:10 -04:00
2017-07-02 16:29:50 -04:00
Location:
* `template` - [**mandatory**] name of source VM. Path is optional.
2017-07-01 12:27:09 -04:00
* `vm_name` - [**mandatory**] name of target VM.
2017-07-01 10:38:50 -04:00
* `folder` - VM folder where target VM is created.
2017-08-15 17:41:36 -04:00
* `host` - [**mandatory**] vSphere host or cluster where target VM is created. If hosts are groupped into folders, full path should be specified: `folder/host` .
2017-06-28 05:19:46 -04:00
* `resource_pool` - by default a root of vSphere host.
2017-08-15 17:41:36 -04:00
* `datastore` - required if target is a cluster, or a host with multiple datastores.
2017-06-28 05:19:46 -04:00
* `linked_clone` - create VM as a linked clone from latest snapshot. `false` by default.
2017-06-27 05:07:10 -04:00
Hardware customization:
2017-07-01 11:03:52 -04:00
* `CPUs` - number of CPU sockets. Inherited from source VM by default.
2017-07-01 16:43:40 -04:00
* `CPU_reservation` - Amount of reserved CPU resources in MHz. Inherited from source VM by default.
2017-07-01 16:52:35 -04:00
* `CPU_limit` - Upper limit of available CPU resources in MHz. Inherited from source VM by default, set to `-1` for reset.
2017-07-01 11:32:16 -04:00
* `RAM` - Amount of RAM in megabytes. Inherited from source VM by default.
2017-07-01 17:02:49 -04:00
* `RAM_reservation` - Amount of reserved RAM in MB. Inherited from source VM by default.
2017-07-01 17:50:01 -04:00
* `RAM_reserve_all` - Reserve all available RAM (bool). `false` by default. Cannot be used together with `RAM_reservation` .
2017-12-01 06:09:47 -05:00
* `disk_size` - Change the disk size (in GB). VM should have a single disk. Cannot be used together with `linked_clone` .
2018-01-16 06:32:22 -05:00
* `NestedHV` - Allows to enable nested hardware virtualization for VM.
2017-05-31 05:49:28 -04:00
2017-07-01 12:27:09 -04:00
Provisioning:
* `ssh_username` - [**mandatory**] username in guest OS.
2017-08-31 08:05:26 -04:00
* `ssh_password` or `ssh_private_key_file` - [**mandatory**] password or SSH-key filename to access a guest OS.
2017-07-01 12:27:09 -04:00
2017-06-27 05:07:10 -04:00
Post-processing:
2017-06-28 05:19:46 -04:00
* `shutdown_command` - VMware guest tools are used by default.
2017-07-01 11:32:16 -04:00
* `shutdown_timeout` - [Duration ](https://golang.org/pkg/time/#ParseDuration ) how long to wait for a graceful shutdown. 5 minutes by default.
2017-06-28 05:19:46 -04:00
* `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.
2017-06-27 05:07:10 -04:00
## Complete Example
2017-05-14 18:15:24 -04:00
```json
{
2017-06-28 05:19:46 -04:00
"variables": {
"vsphere_password": "secret",
"guest_password": "secret"
},
"builders": [
{
"type": "vsphere",
2017-07-01 11:54:10 -04:00
"vcenter_server": "vcenter.domain.com",
2017-06-28 05:19:46 -04:00
"username": "root",
"password": "{{user `vsphere_password` }}",
2017-07-01 12:16:22 -04:00
"insecure_connection": true,
"datacenter": "dc1",
2017-06-28 05:19:46 -04:00
2017-07-02 16:29:50 -04:00
"template": "folder/ubuntu",
2017-06-28 05:19:46 -04:00
"vm_name": "vm-1",
2017-07-05 18:23:39 -04:00
"folder": "folder1/folder2",
2017-08-15 17:41:36 -04:00
"host": "folder/esxi-1.domain.com",
2017-06-28 05:19:46 -04:00
"resource_pool": "pool1/pool2",
"datastore": "datastore1",
"linked_clone": true,
2017-07-01 11:03:52 -04:00
"CPUs": 2,
2017-07-01 16:43:40 -04:00
"CPU_reservation": 1000,
2017-07-01 16:52:35 -04:00
"CPU_limit": 2000,
2017-07-01 11:32:16 -04:00
"RAM": 8192,
2017-07-01 17:02:49 -04:00
"RAM_reservation": 2048,
2017-06-28 05:19:46 -04:00
"ssh_username": "root",
"ssh_password": "{{user `guest_password` }}",
"shutdown_command": "echo '{{user `guest_password` }}' | sudo -S shutdown -P now",
2017-07-01 11:32:16 -04:00
"shutdown_timeout": "5m",
2017-06-28 05:19:46 -04:00
"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"
]
}
]
2017-05-14 18:15:24 -04:00
}
```