Packer: Allow files/subdirectories to be excluded when uploading a directory with the file provisioner

Created on 5 Jan 2015  路  5Comments  路  Source: hashicorp/packer

I'm uploading a Rails app to the machine built by Packer. I'd like to use the file provisioner to upload my directory, but exclude certain files or subdirectories like tmp/, log/, and public/uploads/ from the source. Ideally, the Packer template would look something like this:

{
  "variables": {},
  "builders": [],
  "provisioners": [{
    "type": "file",
    "source": ".",
    "destination": "/var/www/myapp",
    "exclude": ["tmp/", "log/", "public/uploads/"]
  }]
}

I haven't learned Go yet, but from browsing the source code it seems like these two lines would be good starting points:

https://github.com/mitchellh/packer/blob/b6ae00fc370ac2c48c9187c6d341eb5e5e6c8d14/provisioner/file/provisioner.go#L42

https://github.com/mitchellh/packer/blob/b6ae00fc370ac2c48c9187c6d341eb5e5e6c8d14/provisioner/file/provisioner.go#L82

For anyone else with this issue, the first workaround is to upload the entire directory to a temporary destination, then use a shell provisioner afterwards to copy the desired files/dirs to the final destination. The second workaround is to use multiple file provisioners in your Packer template to upload each of the desired files/directories one-by-one.

Both of these workarounds currently work for my use case, but an "exclude" option built into the file provisioner would be more simple, clean, and awesome. :+1:

enhancement good first issue provisionefile wontfix

All 5 comments

:+1:

:+1:
for case when packer config dir is stored with its provisioner role and you don't want to upload iso or previous box :)

This would be perfect. NodeJS projects with lots of dependencies cause the file upload step to hang for a long time due how large the node_modules/ directory is.

May be i can do that after some time if nobody wants.

This seems like it could be handy. to quote @cbednarski in #2872

We do have include / exclude filtering in some other packer features but this turns out to be very confusing for people to use because you cannot inspect the list of files in advance.

Will be happy to look at any PRs that come in for this, but this is not something we're targeting for 1.0, so I'm going to close this. Please see the mailing list for more details on 1.0.

Was this page helpful?
0 / 5 - 0 ratings