packer-cn/README.md

121 lines
3.4 KiB
Markdown
Raw Normal View History

2017-06-27 05:07:10 -04:00
# Packer Builder for VMware vSphere
This builder 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](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-06-27 05:07:10 -04: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
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 10:18:54 -04:00
"vcenter_host": "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
### Required
2017-07-01 10:18:54 -04:00
* `vcenter_host` - vCenter hostname.
2017-06-28 05:19:46 -04:00
* `username` - vSphere username.
* `password` - vSphere password.
* `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.
2017-06-27 05:07:10 -04:00
### Optional
Destination:
2017-06-28 05:19:46 -04:00
* `dc_name` - required if there are several datacenters.
* `folder_name` - 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. `false` by default.
2017-06-27 05:07:10 -04:00
Hardware customization:
2017-06-28 05:19:46 -04:00
* `cpus` - number of CPU sockets. Inherited from source VM by default.
* `ram` - Amount of RAM in megabytes. Inherited from source VM by default.
2017-05-31 05:49:28 -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.
* `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 10:18:54 -04:00
"vcenter_host": "vcenter.domain.com",
2017-06-28 05:19:46 -04:00
"dc_name": "dc1",
"username": "root",
"password": "{{user `vsphere_password`}}",
"template": "ubuntu",
2017-07-01 09:18:54 -04:00
"folder_name": "folder1/folder2",
2017-06-28 05:19:46 -04:00
"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",
"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
}
```