packer vmware-iso build keeps the VM in the vCenter server

298 views
Skip to first unread message

Prakash Kumar

unread,
Jul 19, 2017, 8:42:41 AM7/19/17
to Packer
After successful packer build the the transient VM gets removed from the ESXi host, but it is not getting removed completely. Because we still see the orphaned VM in the vCenter server.
Please let me know how to remove the VM from the vCenter Server as well, can we do that as part of as packer post-processors?




Alvaro Miranda Aguilera

unread,
Jul 19, 2017, 8:44:32 AM7/19/17
to packe...@googlegroups.com
Hello

What do you mean by transient VM?

Screenshot or copy paste of what you see will help.

Alvaro

On Wed, Jul 19, 2017 at 2:42 PM, Prakash Kumar <prak...@gmail.com> wrote:
After successful packer build the the transient VM gets removed from the ESXi host, but it is not getting removed completely. Because we still see the orphaned VM in the vCenter server.
Please let me know how to remove the VM from the vCenter Server as well, can we do that as part of as packer post-processors?




--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/7677611b-5810-49d6-bad0-5846261688a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Prakash Kumar

unread,
Jul 19, 2017, 9:26:21 AM7/19/17
to Packer
Transient VM means the VM which gets created in the remote ESXi host during the packer build and gets removed at the end of the build.

Please find the below JSON file i am using for creating an Ubuntu14.04  OVA.

{
   "variables" : {
       "VM_NAME" : "packer-ubuntu14.04.4-amd64",
       "USER_NAME" : "hcoeuser",
       "PASSWORD" : "hcoeuser",
       "VCENTER_HOST" : "15.116.7.121",
       "VCENTER_USER" : "bfftc...@vsphere.local",
       "VCENTER_PASSWORD" : "Happy.new.year-2016",
       "DATACENTER_NAME" : "Datacenter",
       "ESXi_HOST" : "15.116.2.244",
       "ESXi_USER" : "bfftcvcusr",
       "ESXi_PASSWORD" : "Happy.new.year-2016",
       "ESXi_NETWORK" : "VM Network",
       "ESXi_DATASTORE" : "datastore2"
   },
   "builders": [{
       "name": "ubuntu-14.04.4.amd64.vmware",
       "type": "vmware-iso",
       "guest_os_type": "ubuntu-64",
       "iso_url": "ubuntu-14.04.4-server-amd64.iso",
       "iso_checksum": "2ac1f3e0de626e54d05065d6f549fa3a",
       "iso_checksum_type": "md5",
       "ssh_username": "{{user `USER_NAME`}}",
       "ssh_password": "{{user `PASSWORD`}}",
       "ssh_port": 22,
       "ssh_timeout": "30m",
       "http_directory": "http",
       "headless": "false",
       "boot_wait": "10s",
       "boot_command": [
           "<esc><wait>",
           "<esc><wait>",
           "<enter><wait>",
           "/install/vmlinuz<wait>",
           " auto<wait>",
           " console-setup/ask_detect=false<wait>",
           " console-setup/layoutcode=us<wait>",
           " console-setup/modelcode=pc105<wait>",
           " debian-installer=en_US<wait>",
           " fb=false<wait>",
           " initrd=/install/initrd.gz<wait>",
           " kbd-chooser/method=us<wait>",
           " keyboard-configuration/layout=USA<wait>",
           " keyboard-configuration/variant=USA<wait>",
           " locale=en_US<wait>",
           " netcfg/get_hostname=ubuntu-1404<wait>",
           " netcfg/get_domain=vagrantup.com<wait>",
           " noapic<wait>",
           " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
           " -- <wait>",
           "<enter><wait>"
       ],
       "vm_name" : "{{user `VM_NAME`}}",
       "disk_size": "512000",
       "disk_type_id": "thin",
       "remote_host": "{{user `ESXi_HOST`}}",
       "remote_datastore": "{{user `ESXi_DATASTORE`}}",
       "remote_username": "{{user `ESXi_USER`}}",
       "remote_password": "{{user `ESXi_PASSWORD`}}",
       "remote_type": "esx5",
       "shutdown_command": "echo \"{{user `USER_NAME`}}\"|sudo -S shutdown -P now",
       "format": "ova",
       "tools_upload_flavor": "linux",
       "vmx_data": {
           "config.version": 8,
           "virtualHW.version": 8,
           "ethernet0.networkName": "{{user `ESXi_NETWORK`}}",
           "ethernet0.virtualDev": "e1000",
           "memsize": "49152",
           "numvcpus": "8",
           "cpuid.coresPerSocket": "1",
           "ide0:0.fileName": "disk.vmdk",
           "ide0:0.present": "TRUE",
           "ide0:0.redo": "",
           "scsi0:0.present": "FALSE",
           "RemoteDisplay.vnc.enabled": "TRUE",
           "RemoteDisplay.vnc.port":  "5900"
       }
   }],
   "provisioners": [
       {
           "type": "shell-local",
           "command": "rm -f \"{{user `VM_NAME`}}\"\/\"{{user `VM_NAME`}}\".ova\/\"{{user `VM_NAME`}}\".ova"
       },
       {
           "type": "shell",
           "execute_command": "echo  \"{{user `USER_NAME`}}\"|sudo -S sh '{{.Path}}'",
           "inline": [
               "mkdir -p /opt/hcoe/startup",
               "mkdir -p /opt/hcoe/kubernetes",
               "mkdir -p /opt/hcoe/agent"
           ]
       },
       {
            "type": "file", "source": "scripts/control/firstboot.sh", "destination": "/tmp/firstboot.sh"
       },
       {
           "type": "shell",
           "execute_command": "echo  \"{{user `USER_NAME`}}\"|sudo -S sh '{{.Path}}'",
           "inline": [
               "mv /tmp/firstboot.sh /etc/init.d/firstboot.sh",
               "chown root:root /etc/init.d/firstboot.sh",
               "chmod 755 /etc/init.d/firstboot.sh"
           ]
       },
       {
           "type": "file", "source": "scripts/control/subsboot.sh", "destination": "/tmp/subsboot.sh"
       },
       {
           "type": "shell",
           "execute_command": "echo  \"{{user `USER_NAME`}}\"|sudo -S sh '{{.Path}}'",
           "inline": [
               "mv /tmp/subsboot.sh /etc/init.d/subsboot.sh",
               "chown root:root /etc/init.d/subsboot.sh",
               "chmod 755 /etc/init.d/subsboot.sh"
           ]
       },
       {
           "type": "file", "source": "scripts/control/rc.local", "destination": "/tmp/rc.local"
       },
       {
           "type": "shell",
           "execute_command": "echo  \"{{user `USER_NAME`}}\"|sudo -S sh '{{.Path}}'",
           "inline": [
               "mv -f /tmp/rc.local /etc/rc.local",
               "chown root:root /etc/rc.local",
               "chmod 755 /etc/rc.local"
           ]
       },
       {
           "type": "file", "source": "scripts/startup", "destination": "/tmp/startup"
       },
       {
           "type": "shell",
           "execute_command": "echo  \"{{user `USER_NAME`}}\"|sudo -S sh '{{.Path}}'",
           "inline": [
               "mv /tmp/startup /opt/hcoe/",
               "chown -R root:root /opt/hcoe/*",
               "chmod -R 755 /opt/hcoe/*"
           ]
       },
       {
           "type": "shell",
           "execute_command": "echo  \"{{user `USER_NAME`}}\"|sudo -S sh '{{.Path}}'",
           "script": "scripts/control/postinstall.sh"
       }
   ],
   "post-processors": [
       {
           "type": "shell-local",
           "inline": [
               "ls -ltr \"{{user `VM_NAME`}}\"\/\"{{user `VM_NAME`}}\".ova\/\"{{user `VM_NAME`}}\".ova",
               "chmod 755 \"{{user `VM_NAME`}}\"\/\"{{user `VM_NAME`}}\".ova\/\"{{user `VM_NAME`}}\".ova"
           ]
       },
       {
           "type": "vsphere",
           "host": "{{user `VCENTER_HOST`}}",
           "username": "{{user `VCENTER_USER`}}",
           "password": "{{user `VCENTER_PASSWORD`}}",
           "datacenter": "{{user `DATACENTER_NAME`}}",
           "cluster": "{{user `ESXi_HOST`}}",
           "datastore": "{{user `ESXi_DATASTORE`}}",
           "vm_name": "sanity_ubuntu_14.04_64",
           "insecure": "true",
           "disk_mode": "thin",
           "vm_network": "{{user `ESXi_NETWORK`}}",
           "options": [
               "--powerOn"
           ]
       }
   ]
}





On Wednesday, 19 July 2017 18:14:32 UTC+5:30, Alvaro Miranda Aguilera wrote:
Hello

What do you mean by transient VM?

Screenshot or copy paste of what you see will help.

Alvaro
On Wed, Jul 19, 2017 at 2:42 PM, Prakash Kumar <prak...@gmail.com> wrote:
After successful packer build the the transient VM gets removed from the ESXi host, but it is not getting removed completely. Because we still see the orphaned VM in the vCenter server.
Please let me know how to remove the VM from the vCenter Server as well, can we do that as part of as packer post-processors?




--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.



--
Alvaro

Alvaro Miranda Aguilera

unread,
Jul 19, 2017, 9:57:58 AM7/19/17
to packe...@googlegroups.com
Hello

Thanks


By default on ESXi packer will un-register the VM.

So in a workflow that use OVFTOOLS and shell-local, some people will connect to VCSA and convert the VM to Template, or OVF to OVA, etc, etc.


If you want to keep registered use this:

keep_registered (boolean) - Set this to true if you would like to keep the VM registered with the remote ESXi server. This is convenient if you use packer to provision VMs on ESXi and don't want to use ovftool to deploy the resulting artifact (VMX or OVA or whatever you used as format). Defaults to false.

Thanks
Alvaro

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/47a489f8-2b96-4a9b-93bb-7e471632ddaa%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Prakash Kumar

unread,
Jul 19, 2017, 10:18:16 AM7/19/17
to Packer
Thanks !!

I am deploying the OVA in "post-processors" section just for some basic sanity test. But actually i don't want the VM after the build. As you mentioned by default the packer un-register the VM only from the ESXi host.. but it is not removing it from the VCSA Inventory. please find the below screenshot for more details..

I am able to manually 'Right click' the VM and select "Remove from Inventory" option to delete the VM from VSCA as well.

Regards,
Prakash



--
Alvaro

Alvaro Miranda Aguilera

unread,
Jul 19, 2017, 10:22:27 AM7/19/17
to packe...@googlegroups.com
That is correct, packer won't remove the build.

VCSA may need a refresh after the VM gets unregistered on the ESX host.


you can use OVFTools and shell-local for that too.



To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/c9606d88-80ee-4142-b3c0-9804ed9a8641%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Prakash Kumar

unread,
Jul 19, 2017, 10:35:38 AM7/19/17
to Packer
Thanks !!!

Can you please let me know how to refresh the VCSA using OVFTOOLS and shell-local via packer ?

Is it possible to send the exact lines which i have to add it in my JSON file ?

Regards,
Prakash,.

Alvaro Miranda Aguilera

unread,
Jul 19, 2017, 10:57:16 AM7/19/17
to packe...@googlegroups.com
Hello

Maybe I spoke too fast.

Are 2 tools that you can check. Also as VCSA is a paid product, I would contact VMWare too for more options.

OVFTool:

govc:

Thanks
Alvaro.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Prakash Kumar

unread,
Jul 19, 2017, 2:01:44 PM7/19/17
to Packer
Thanks a Lot !!!   I will get back to you if i need any other help.

-Prakash
Reply all
Reply to author
Forward
0 new messages