packer-cn/README.md

114 lines
3.9 KiB
Markdown
Raw Normal View History

2017-05-14 18:15:24 -04:00
# packer-builder-vsphere
2017-05-31 05:49:28 -04:00
## Builder parameters
### Required parameters:
* `username`
* `password`
* `template`
* `vm_name`
* `host`
### Optional parameters:
* Destination parameters:
* `resource_pool`
* `datastore` (but is required if you move between hosts)
* Hardware configuration:
* `cpus`
* `ram`
* `shutdown_command`
* `ssh_username`
* `ssh_password`
* `dc_name` (source datacenter)
You will find an example in **Installation instructions** section.
## Progress bar
You can find it [here](https://github.com/LizaTretyakova/packer-builder-vsphere/projects/1) as well.
- [x] hardware customization of the new VM (cpu, ram)
- [x] clone from template (not only from VM)
- [x] clone to alternate host, resource pool and datastore
- [ ] enable linked clones
- [ ] support Windows guest systems
- [ ] enable VM-to-template conversion
- [ ] tests
- [ ] add a shutdown timeout
- [ ] further hardware customization:
* resize disks
* ram reservation
* cpu reservation
2017-05-14 18:15:24 -04:00
## Installation instructions
2017-05-31 05:40:12 -04:00
1. It is supposed that you already have Go(and [Packer](https://github.com/hashicorp/packer)), [Docker-compose](https://docs.docker.com/compose/install/) and [Glide](https://github.com/Masterminds/glide) set.
2017-05-14 18:15:24 -04:00
1. Download the sourcces from [github.com/LizaTretyakova/packer-builder-vsphere](github.com/LizaTretyakova/packer-builder-vsphere)
2017-05-31 05:40:12 -04:00
1. `cd` to `$GOPATH/go/src/github.com/LizaTretyakova/packer-builder-vsphere` (or wherever it was downloaded)
2017-05-14 18:15:24 -04:00
2017-05-31 05:40:12 -04:00
1. Get the dependencies
2017-05-15 09:11:01 -04:00
```
$ glide install
```
2017-05-31 05:40:12 -04:00
5. Build the binaries
2017-05-14 18:15:24 -04:00
```
2017-05-16 01:49:32 -04:00
$ docker-compose run build
2017-05-14 18:15:24 -04:00
```
2017-05-31 05:40:12 -04:00
6. The template for this builder is like following:
2017-05-14 18:15:24 -04:00
```json
{
"variables": {
"url": "{{env `YOUR_VSPHERE_URL`}}",
"username": "{{env `YOUR_VSPHERE_USERNAME`}}",
"password": "{{env `YOUR_VSPHERE_PASSWORD`}}",
"ssh_username": "{{env `TEMPLATE_VM_SSH_USERNAME`}}",
"ssh_password": "{{env `TEMPLATE_VM_SSH_PASSWORD`}}",
"dc_name": "{{env `TEMPLATE_VM_DATACENTER`}}",
2017-05-31 05:40:12 -04:00
"template": "{{env `TEMPLATE_VM_NAME`}}",
"host": "{{env `TARGET_HOST`}}"
2017-05-14 18:15:24 -04:00
},
"builders": [
{
"type": "vsphere",
"url": "{{user `url`}}",
"username": "{{user `username`}}",
"password": "{{user `password`}}",
"ssh_username": "{{user `ssh_username`}}",
"ssh_password": "{{user `ssh_password`}}",
"dc_name": "{{user `dc_name`}}",
"template": "{{user `template`}}",
"vm_name": "new_vm_name",
2017-05-31 05:40:12 -04:00
"host": "{{user `host`}}",
"resource_pool": "your_target_resource_pool",
"datastore": "your_target_datastore",
2017-05-14 18:15:24 -04:00
"RAM": "1024",
"cpus": "2",
"shutdown_command": "echo '{{user `ssh_password`}}' | sudo -S shutdown -P now"
}
2017-05-14 18:27:14 -04:00
],
"provisioners": [
{
"type": "shell",
"inline": ["echo foo"]
}
2017-05-14 18:15:24 -04:00
]
}
```
where `vm_name`, `RAM`, `cpus` and `shutdown_command` are parameters of the new VM.
Parameters `ssh_*`, `dc_name` (datacenter name) and `template` (the name of the base VM) are for the base VM,
2017-05-31 05:40:12 -04:00
on which you are creating the new one (note that VMWare Tools should be already installed on this template machine).
`vm_name` and `host` (describe the name of the new VM and the name of the host where we want to create it) are required parameters; you can also specify `resource_pool` (if you don't, the builder will try to detect the default one) and `datastore` (**important**: if your target host differs from the initial one, you **have to** specify `datastore`; in case you stay within the same host, this parameter can be omitted).
2017-05-14 18:15:24 -04:00
`url`, `username` and `password` are your vSphere parameters.
You need to set the appropriate values in the `variables` section before proceeding.
2017-05-31 05:40:12 -04:00
7. Now you can go to the `bin/` directory
2017-05-14 18:15:24 -04:00
```
$ cd ./bin
```
and try the builder
```
$ packer build template.json
```