Packer: winrm upload hangs packer 1.2.5+

Created on 19 Sep 2018  ยท  7Comments  ยท  Source: hashicorp/packer

Hi all,

For some reason I'm unable to upload a config file for chocolatey. I have everything else disabled and still nothing. This worked fine in version 1.2.4, but doesn't work in any subsequent version. Other files upload fine. The file is in the gist below. Any ideas what could be causing this?

Packer version: 1.2.5+
Host platform: windows
Debug/packer config: https://gist.github.com/hoshsadiq/315904b619830c1cac35cb32786e9c86

Thanks

communicatowinrm provisionefile

Most helpful comment

I'm reopening until I get a chance to merge the docs update and file check I promised earlier :D

All 7 comments

This was introduced by 36df317b892c11e4929ae657706aae61a547c4b8; I'll look into why it hangs instead of failing, but for now try "destination": "C:\\Windows\\Temp\\" to make it clear it's a directory

So a bit more context on this.

Packer doesn't know anything about the guest OS. It just knows what commands you want run against it, and does those. This makes it really hard for packer to intuit intent, but it does mean that we can avoid a lot of system-based special casing. Essentially, the philosophy is that it's the user's job to understand that special casing.

That said, back in Packer 1.2.4 I violated that philosophy and tried to make our uploader a tiny bit "smarter" by doing a test to see whether the remote location was a file or a directory. This worked for the vast majority of cases but broke in situations where users didn't have powershell installed, which isn't great. So we reverted it.

The upshot of this is that Packer doesn't know whether the remote path is a file or a directory, and it can't reliably test to find out. So Packer assumes it's a file. Only if the user has ended the directory path with a file separator ("/" or "\") does Packer feel confident enough to do some magic to add the basename from the source file to the directory provided in the destination file.

I just looked into what it would take to modify the winrmcp code to do this magic for packer, but it's not a trivial change and I'm concerned I would break other things. However, I do feel safe adding an explicit exit so that Packer fails rather than hanging. So I've made a PR against the winrmcp project and I'll update the winrmcp dependency once that's merged, as well as adding an error message with a suggestion that your path name may be at fault, and updating documentation to make it clear that directories should end in "/".

Thank you for that! That'll be much help.

That said, back in Packer 1.2.4 I violated that philosophy and tried to make our uploader a tiny bit "smarter" by doing a test to see whether the remote location was a file or a directory

At the expense of breaking the philosophy (again), could this not be done using batch? Something like if exist %1\* echo DirExists?

_probably, yes_. However, I'm pretty hesitant at this point because every time I touch this code to try to make it better I break an edge case.

Doing this would also mean that the winrm communicator (and not the ssh communicator) would be able to do this kind of check-based repair, which leads to further inconsistency. In the end I think that requiring an explicit file path is better anyway, and forcing good habits keeps Packer simpler and also less frustrating/confusing for new users.

Makes perfect sense! Thanks for the help!

I'm reopening until I get a chance to merge the docs update and file check I promised earlier :D

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sourav82 picture sourav82  ยท  3Comments

mvermaes picture mvermaes  ยท  3Comments

jesse-c picture jesse-c  ยท  3Comments

tleyden picture tleyden  ยท  3Comments

wduncanfraser picture wduncanfraser  ยท  3Comments