Packer: Vsphere post-processor issue

Created on 16 Oct 2017  路  18Comments  路  Source: hashicorp/packer

packer --version
1.1.0
Host platform: OSX

Having issues with using the vsphere post processor with uploading the vmx to vsphere. I'm not sure if it's something to do with special characters in the vsphere username and password which require them to be escaped?

Template: template gist
Debug log: debug gist

post-processovsphere question

All 18 comments

glancing at the code, it doesn't appear that packer does any escaping for you. It plugs in the password you provide to a uri using this pattern:

    ovftool_uri := fmt.Sprintf("vi://%s:%s@%s/%s/host/%s",
        url.QueryEscape(p.config.Username),
        password,
        p.config.Host,
        p.config.Datacenter,
        p.config.Cluster)

@SwampDragons thanks for checking that out!

Not too sure what the issue could be then...

Just messed with the test for that post-processor to see what happens when we build the arguments; turns out we do actually encode them... so your

"password with special characters: eg &$%@asdf1"

would become the following URI

vi://me:password+with+special+characters%3A+eg+%26%24%25%40asdf1@myhost......

So you shouldn't have to do any escaping/encoding on your own.

I see, from the gists would you say it is the username/password is the issue then?

Not if the real username and password are formatted the same way as you have in your gist... that looks right to me. I assume you're able to upload outside of packer?

oh! Could it be the datacenter? You're escaping it here so it'd get encoded weirdly:

"datacenter": "vsphere\\ srv\\ host",

to

vi://me:password+with+special+characters%3A+eg+%26%24%25%40asdf1@myhost/vsphere\ srv\ host/host/mycluster

Oh right, yeah, I was escaping it there as well (I previously wasn't!)

Awesome -- let me know if that fixes things for you and make sure you don't have any other escape sequences in the components of that final URI

Cool, so basically don't do any escaping is what you're suggesting?

yep, except normal string escaping. For example, you have to escape "this has a quote" inside the string" or the json would be invalid.

hahaha github formatted the middle quote so you can't see it but I escaped it with a backslash.

Okay great - don't think I have time to check it out this weekend, but will get back to you on Monday! Thanks :)

@SwampDragons sorry for taking a while to look at this again!

Been looking at it again, and I can get the ovftool working normally on the command line, but having to escape my password, as well as escape the datacenter with single slashes as I previously was doing it.

The command looks something like:

ovftool --acceptAllEulas --name=vsphere_post_processor_upload --datastore=datastore-01 --noSSLVerify=true --diskMode=thin --vmFolder=Test --network="VM Network" /Users/Projects/vmware/win_base.vmwarevm/win_base.vmx vi://[email protected]:\&[email protected]/Vsphere\ Srv\ Host/host/Production

And this successfully uploads the file to the vsphere endpoint (password is intentional with the backslash, as is the blackslashes to escape the data center name).

When running the vsphere post processor with the following template:

    "post-processors": [
        {
            "type": "vsphere",

            "datacenter": "Vsphere Srv Host",
            "cluster": "Production",
            "host": "server-01.company.com",
            "datastore": "datastore-01",

            "username": "[email protected]",
            "password": "&passW0rd",
            "insecure": "true",
            "keep_input_artifact": true,

            "vm_folder": "Test",
            "vm_name": "vsphere_post_processor_upload",
            "vm_network": "\"VM Network\"",
            "disk_mode": "thin",
            "overwrite": false
        }
    ]

It generates this ovftool command from the PACKER_LOGS:

--acceptAllEulas --name=vsphere_post_processor_upload --datastore=datastore-01 --noSSLVerify=true --diskMode=thin --vmFolder=Test --network="VM Network" /Users/Projects/vmware/win_base.vmwarevm/win_base.vmx vi://user.name%40company.com:<password>@server-01.company.com/Vsphere Srv Host/host/Production

I feel like some kind of escaping is being missed, or I'm missing somewhere? IE for the vm_network I needed to quote as there was a space in the name.

Any ideas?

Are you sure you need to quote because of the space in the name? I think the encoding should handle that.

@SwampDragons Well, if I don't quote the network, it still fails, and when I take the command and try it manually it fails in a different way with something along the lines of:

Error: Unexpected option: vi://server-01.company.com/Vsphere

With the manual ovftool command looking like:

ovftool --acceptAllEulas --name=vsphere_post_processor_upload --datastore=VMFS-DATA01 --noSSLVerify=true --diskMode=thin --vmFolder=Test --network=VM Network /Users/Projects/vmware/win_base.vmwarevm/win_base.vmx vi://server-01.company.com/Vsphere Srv Host/host/Production

So I'm quite confused...

Testing again, it's now working! So even more confused, but removing the quotes in the VM Network fixed it within the template!

Thanks for the help! :)

Gotta love the Heisenbugs. Glad it's resolved; reopen if something else comes up. I think some better docs around quoting may be called for.

Yeah will do! Thanks for your help though, much appreciated :)

Was this page helpful?
0 / 5 - 0 ratings