Packer – vSphere JSON Auto Import

Standard

Layout of my JSON file which automatically uploads and registers the VM in my vCenter.

JSON File with Automated registration in vCenter:

{
 "variables": {
       "remote_host": "192.168.198.50",
       "myhost": "rhdev100",
       "mydomain": "rocksolid.com",
       "myip": "192.168.198.100",
       "mygw": "192.168.198.2",
       "mymask": "255.255.255.0",
       "mydns1": "192.168.198.2",
       "mydns2": "192.168.198.3",
       "mydatastore": "datastore8gbesx1"
       },
 "builders": [
    {
     "boot_command": [
       "<tab>",
       "vmlinuz initrd=initrd.img ",
       "myhostname={{user `myhost`}} ",
       "mydomain={{user `mydomain`}} ",
       "myip={{user `myip`}} ",
       "mygateway={{user `mygw`}} ",
       "mynetmask={{user `mymask`}} ",
       "mydns1={{user `mydns1`}} ",
       "mydns2={{user `mydns2`}} ",
       "ks=http://192.168.198.1:8000/Build/kickstart/rh.cfg <enter><wait>"
      ],
       "boot_wait": "5s",
       "disk_size": 4098,
       "guest_os_type": "rhel6-64",
       "headless": false,
       "http_directory": "http",
       "iso_checksum": "32c7695b97f7dcd1f59a77a71f64f2957dddf738",
       "iso_checksum_type": "sha1",
       "iso_url": "http://192.168.198.1:8000/packer/ISO/CentOS-6.5-x86_64-bin-DVD1.iso",
       "output_directory": "{{user `myhost`}}",
       "name": "rhel6-64",
       "shutdown_command": "shutdown -h now",
       "skip_compaction": false,
       "ssh_password": "SecretPasswd",
       "ssh_port": 22,
       "ssh_username": "root",
       "ssh_wait_timeout": "10000s",
       "tools_upload_flavor": "linux",
       "type": "vmware-iso",
       "vmx_data": {
              "ethernet0.networkName": "VM Network",
              "ethernet0.present": "TRUE",
              "ethernet0.virtualDev": "vmxnet3",
              "cpuid.coresPerSocket": "1",
              "memsize": "480",
              "numvcpus": "1",
              "scsi0:0.fileName": "disk.vmdk",
              "scsi0:0.present": "TRUE",
              "scsi0:0.redo": ""
      }
    }
  ],
       "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",
                     "scripts/eth1toeth0.sh"
              ],
              "type": "shell"
              }
       ],
       "post-processors": [
              {
              "type": "vsphere",
              "host": "vc01.rocksolid.com",
              "username": "TheDude",
              "password": "SecretPasswd",
              "datacenter": "DC01",
              "cluster": "Lab",
              "resource_pool": " ",
              "datastore": "{{user `mydatastore`}}",
              "vm_folder": "CentOS",
              "vm_name": "{{user `myhost`}}", 
              "vm_network": "VM Network",
              "insecure" : "true"
              }
       ]
}

Leave a Reply