I have a VMWARE image running CentOS.I want to create a vagrant box from it with packer. I am new to Vagrant and can anyone suggest the steps?
2 Answers
Using Packer to apply additional provisioning steps to an existing VM is supported by Packer via the vmware-vmx builder
This VMware Packer builder is able to create VMware virtual machines from an existing VMware virtual machine (a VMX file). It currently supports building virtual machines on hosts running VMware Fusion Professional for OS X, VMware Workstation for Linux and Windows, and VMware Player on Linux.
In your situation where you have an existing CentOS VMX and want to turn it into a Vagrant box you would create packer.json configuration file like so:
{
"builders": [{
"type": "vmware-vmx",
"source_path": "/path/to/a/vm.vmx",
"ssh_username": "root",
"ssh_password": "root",
"ssh_wait_timeout": "30s",
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
}],
"provisioners": [{
"type": "shell",
"inline": ["echo 'my additional provisioning steps'"]
}],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": true,
"output": "mycentos.box"
}]
}
Packer would clone the source VMX, boot the box, apply any provisioning steps you had, shut down the box, and then output a new Vagrant ".box" file.

- 2,546
- 20
- 22
-
1thanks. However, I got an error "Build 'vmware-vmx' errored: Timeout waiting for SSH.". The ssh username and password are correct. How to fix this? – vaj oja Jul 10 '15 at 07:24
It sounds like you won't be able to. Packer assumes a base box (for vagrant) and ends at a new box. You can't go from a running VM to a box via Packer.
If you started the CentOS VM using vagrant, you can do vagrant export
If you have a running VM you made manually, your best bet is to start over using a Vagrant box. If you want to continue with this route: http://docs.vagrantup.com/v2/vmware/boxes.html

- 3,854
- 3
- 18
- 22