Packer: Allow include/exclude for file provisioner

Created on 30 Jul 2020  ยท  5Comments  ยท  Source: hashicorp/packer

It seems #1811 was closed as won't fix for....no other reason than it would be confusing.

This is a misstep as having that functionality would severely improve the usability of the file provisioner, without having to have multiple steps or convoluted shell/powershell code to clean up after it.

Please consider adding this feature.

enhancement help wanted provisionefile

All 5 comments

Aside-meta-note: closing issues as "wontfix" with a version target is fundamentally confusing and sends mixed messages. By all means, target for whatever future version, but closing it is a pretty clear "not gonna happen".

But yeah, please provide for this. I'd like to be able to upload the contents of a git repo without having to wait half an hour for it to slowly upload the .git hidden folder and then have to delete it after the fact. This is a basic useability feature, I don't know how y'all failed to include it in the initial implementation.

Hello there, thanks for opening; I think this should be solved with the hcl2 fileset function !

I think you're right that the rationale for having closed the original issue was weak. This would be a nice UI improvement.

Probably the right way to address this in the provisioner itself rather than the hcl2 fileset function would be to change the UploadDir call here https://github.com/hashicorp/packer/blob/master/provisioner/file/provisioner.go#L180 to a directory-walking function that checks against an "exlcude" list that the user can pass in as an option to the provisioner.

Since it does look like HCL provides a built-in solution for this, I probably won't direct the Packer team to work on it, but I'd be happy to review a community PR that does this.

Maybe I'm missing something, but I don't see any way to exclude specific files or directories using HCL2's fileset. I'd be happy to switch to HCL2 if it can provide an actual solution.

Hello there, yes sorry, my previous message was rather short.

The HCL fileset function allows to specifically and recursively select files with a glob pattern. So it's only 'include' but it can be exclusive depending on how you call it, so to take the docs page example, if you have:

> tree pkr-consul
pkr-consul
โ”œโ”€โ”€ build-linux.pkr.hcl
โ””โ”€โ”€ linux
    โ”œโ”€โ”€ files
    โ”‚   โ”œโ”€โ”€ hello.txt
    โ”‚   โ””โ”€โ”€ world.txt
    โ””โ”€โ”€ scripts
        โ”œโ”€โ”€ README.txt
        โ”œโ”€โ”€ script.bash
        โ”œโ”€โ”€ script-1-install.sh
        โ””โ”€โ”€ script-2-setup.sh

And you only want the .txt suffixed files, you can do:

$ echo 'fileset("**", "*.txt")' | packer console pkr-consul
[
  "../files/hello.txt",
  "../files/world.txt",
  "../linux/scripts/README.txt",
]

or only .sh suffixed files in linux/scripts:

$ echo 'fileset("linux/scripts", "*.sh")' | packer console pkr-consul
[
  "script-1-install.sh",
  "script-2-setup.sh",
]

I'd advise on sorting the fileset after this because fileset will not sort anything ( so depending on how your filesystem works this _might_ differ).

packer console will help you find the best solution.

If that does not help you to solve your problem; please describe your issue a bit more so that we can help you better ๐Ÿ™‚

Was this page helpful?
0 / 5 - 0 ratings