Packer – vSphere JSON Manual Import

Standard

Here is a JSON file to use when you would like to upload your VM to a vCenter. It will upload the VM to your choice of Datastore but it will not import/register the VM. This has to be done manually!

{
	"variables": {
		"remote_host": "192.168.198.51",
		"myhost": "rhdev10",
		"mydomain": "rocksolid.com",
		"myip": "192.168.198.10",
		"mygateway": "192.168.198.2",
		"mynetmask": "255.255.255.0",
		"mydns1": "192.168.198.2",
		"mydns2": "192.168.198.3",
		"fqdn": "CentOS6.5-x86_64",
		"datastore": "datastore8gbesx1"
	  },
	"builders": [
	{  
	"type": "vmware-iso",
	"iso_url": "http://192.168.198.1:8000/packer/ISO/CentOS-6.5-x86_64-bin-DVD1.iso",
	"output_directory": "{{user `myhost`}}",
	"iso_checksum": "32c7695b97f7dcd1f59a77a71f64f2957dddf738",
	"iso_checksum_type": "sha1",
	"disk_size": "4096",
	"disk_type_id": "thin",
	"http_directory": "./",
	"remote_host": "192.168.198.51",
	"remote_datastore": "{{user `datastore`}}",
	"remote_username": "root",
	"remote_password": "SecretPasswd",
	"remote_type": "esx5",
	"ssh_username": "root",
	"ssh_password": "SecretPasswd",
	"ssh_port": 22,
	"ssh_wait_timeout": "720s",
	"shutdown_command": "shutdown -h now",
	"boot_command": [
		"<tab>",
		"vmlinuz initrd=initrd.img ",
		"myhostname={{user `myhostname`}} ",
		"mydomain={{user `mydomain`}} ",
		"myip={{user `myip`}} ",
		"mygateway={{user `mygateway`}} ",
		"mynetmask={{user `mynetmask`}} ",
		"mydns1={{user `mydns1`}} ",
		"mydns2={{user `mydns2`}} ",
		"ks=http://192.168.198.1:8000/Build/kickstart/rh.cfg <enter><wait>"
      ],
      "boot_wait": "20s",
      "vm_name": "{{user `fqdn`}}",
      "vmx_data": {
      	"virtualHW.version": "9",
        "ethernet0.networkName": "VM Network",
        "ethernet0.present": "TRUE",
		"ethernet0.virtualDev": "vmxnet3",
        "memsize": "512",
        "numvcpus": "1",
        "cpuid.coresPerSocket": "1",
        "scsi0:0.fileName": "disk.vmdk",
        "scsi0:0.present": "TRUE",
        "scsi0:0.redo": "",
        "ide0:0.present": "FALSE"
      }
    }
  ],
	"provisioners": [
		{
		"type": "file",
		"source": "/Users/TheDude/Build/VMware/VMwareTools-9.6.1-1378637.tar.gz",
		"destination": "/tmp/VMwareTools-9.6.1-1378637.tar.gz"
		},
		{
		"execute_command": "echo 'TheDude' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
		"scripts": [
			"scripts/yum.sh",
			"scripts/sysctl.sh",
			"scripts/vmtools.sh",
			"scripts/network.sh"
		],
		"type": "shell"
		}
	]
}

Leave a Reply