vsphere post-provisioner convert to template

626 views
Skip to first unread message

Jon Hittner

unread,
Aug 3, 2016, 3:52:15 PM8/3/16
to Packer
I'm using the vsphere post-provisioner to upload the vmx output from the vmware-iso builder to my vcenter.   It works well, but the result is a virtual machine.   Is there any way to have the provisioner convert the virtual machine to a template, or does anyone have a workflow that already does this?

Stan Dorsett

unread,
Aug 3, 2016, 4:48:45 PM8/3/16
to packe...@googlegroups.com

On Wed, Aug 3, 2016 at 2:52 PM, Jon Hittner <jhittn...@gmail.com> wrote:
I'm using the vsphere post-provisioner to upload the vmx output from the vmware-iso builder to my vcenter.   It works well, but the result is a virtual machine.   Is there any way to have the provisioner convert the virtual machine to a template, or does anyone have a workflow that already does this?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/7947f7e7-45c6-43bc-9e0c-7dace856daa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Hittner

unread,
Aug 3, 2016, 5:38:36 PM8/3/16
to Packer
Thanks, but unfortunately that doesn't work in my case as we don't use virtualbox/vagrant.   We are using the vmware-iso builder to build the image using a remote esxi box (remote_type esx5) and the the vsphere post-processor to upload to our vcenter.   Unless Im missing it, I don't think the ovftool has the ability to convert a vmware virtual machine on a vsphere to a vmware template.   

Maybe there is a way to do it during the builder phase after the machine is shutdown as a final step.   The esxi shell has a "vim-cmd vmsvc/convert.toTemplate" although I havent figured out how to get the builder to run a command on the remote esxi machine that the image is being built, or how to pass it the vmid that that command would need.

any ideas?

-Jon

Becky

unread,
Aug 4, 2016, 1:24:21 AM8/4/16
to Packer
Hi Jon,

Try out these  steps 

variables.json
==============

{
    "esxi_host": "xxx.xxx.xxx.xxx",
    "esxi_username": "root",
    "esxi_password": "PassWordGoesHere"
}



runESXiCommands.json
===================
{
    "builders": [{
        "type": "null",
        "name": "BUILDER-EXEC-ESXI-CMD",
        "ssh_host": "{{user `esxi_host`}}",
        "ssh_username": "{{user `esxi_username`}}",
        "ssh_password": "{{user `esxi_password`}}"
    }],
    "provisioners": [{
        "type": "shell",
        "only": ["BUILDER-EXEC-ESXI-CMD"],
        "scripts": [
            "runESXiCommands.sh"
        ]
    }
    ]
}


runESXiCommands.sh << This script  will be executed on ESXi and make sure that SSH is Open on ESXi >>
==================
#!/bin/sh

vim-cmd vmsvc/convert.toTemplate


packer validate -var-file=variables.json runESXiCommands.json

packer build -only=BUILDER-EXEC-ESXI-CMD -var-file=.variables.json runESXiCommands.json


Regards,

Jon Hittner

unread,
Aug 4, 2016, 10:34:15 AM8/4/16
to Packer
cool, thanks Becky.  It looks like Im almost there, the null builder does exactly what I want and executes on the ESXi instead of the VM.. Now I need to find a way to have the null builder wait until after the vmware-iso builder is run before it starts. 

 The run order I need would look something like:

1- vmware-iso builder 
2- all provisioners used by vmware-iso (wait till complete)
3- null builder
4- script provisioner used by null builder
5- vsphere post processor

Is there a way to get one builder to wait on the other before starting?   Am I approaching this wrong?

-Jon

Becky

unread,
Aug 4, 2016, 11:00:36 PM8/4/16
to Packer
Hi Jon,

No there is no such way which i am aware of but this is what you can do..

write a master.sh script 

MASTER.sh
===============
#!/bin/bash

function packerValidate()
{
packer validate -var-file=variables.json runESXiCommands.json

packer validate -var-file=variables.json runESXiCommands2.json


}

function packerBuildSerialOrder()
{
packer build -only=BUILDER-EXEC-ESXI-CMD1 -var-file=.variables.json runESXiCommands1.json

packer build -only=BUILDER-EXEC-ESXI-CMD2 -var-file=.variables.json runESXiCommands2.json
}

packerValidate
packerBuildSerialOrder

==================

Hope above helps.

Regards,

Rodrigo P.

unread,
Oct 19, 2016, 2:55:21 PM10/19/16
to Packer
Hi Jon,

I was wondering how you got to work the combination of vmware-iso on remote esxi and vsphere post-processor. I couldn't get this to work, and I assumed it was because the vsphere post-processor expects the VM files in some output directory where packer was executed, but instead it's on the ESXi datastore. Can you offer some hint about it?

thanks in advance,
rodrigo

murali U

unread,
Jun 16, 2017, 10:52:39 AM6/16/17
to Packer
Hi Rodrigo/Jon,

Did either of you figure our creating vmtx files or templates using packer. If so, can you advise on how to do this please? 

cheers

Rickard von Essen

unread,
Jun 17, 2017, 8:58:50 AM6/17/17
to packe...@googlegroups.com

James Paley

unread,
Jun 26, 2017, 1:02:46 PM6/26/17
to Packer
Note that in your terraform script, the disk section -> template parameter can refer to a vsphere virtual machine, which will result in a clone of the virtual machine, pretty much just like a template.
Reply all
Reply to author
Forward
0 new messages