-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
packer Post Processor Ignores User Variables in "only" #4895
Comments
@mitchellh Help required |
You can't use user variables in only. You have to hardcode |
"builders": [ "provisioners": [ Debug mode enabled. Builds will not be parallelized. So i know the build name is taking effect. Error initializing core: 1 error(s) occurred:
Now if i change "name": "{{user |
You're right; this is the same issue. It's an artifact of how and when we interpolate variables. Fixing it would require a serious architectural rewrite, so it probably won't happen before Packer 2.0. |
Ok thanks, yeah having the "only" and "except" only work for hardcoded strings is kind of limiting. Basically it would nice to have a way to only run certain provisioners based on some kind of user input. Thanks. |
Understood; normally people who need this kind of flexibility wrap their packer run in a json-parser that can format the template how they need. |
If variables can not be supported, would it be possible to support regex? Our builders are named like the following:
Where
|
No, sorry -- based on the architecture of Packer, regex would be just as hard to support as user variables. I'm going to mark this with the "config 2.0" flag -- we're in the beginning stages of a push to switch to using HCL2 templates and this may be something we can achieve during that refactor. |
Here is what kind of worked for me when using the shell provisioner: builder And after that I use the shell provisioner like this:
Case 1: the shell script is being executed for production. PACKER_BUILD_NAME |
Hello there, closing this issue as it should now work to set only/except from a variable using HCL2, the whole array could be a variable: variable "my_only" {
default = ["this_builder", "that_builder"]
}
#........
build {
#........
post-processor {
only = var.my_only
}
} |
Ah wait, this is not possible yet: In order to make this work we will have to pass the HCL2 eval context into this function first; packer/hcl2template/types.build.post-processor.go Lines 25 to 36 in cf514d3
|
Hi! |
…11094) feature + tests. Including in: * name * only * except * keep_input_artifact Example file: ```hcl source "null" "example1" { communicator = "none" } source "null" "example2" { communicator = "none" } locals { except = "null.example1" } variable "only" { default = "null.example1" } build { sources = ["source.null.example1", "source.null.example2"] post-processor "shell-local" { except = [local.except] inline = ["echo first post-processor"] } post-processor "shell-local" { only = [var.only] inline = ["echo second post-processor"] } } ``` Ouput: ```shell-session $ packer build foo.pkr.hcl null.example1: output will be in this color. null.example2: output will be in this color. ==> null.example1: Running post-processor: (type shell-local) ==> null.example2: Running post-processor: (type shell-local) ==> null.example2 (shell-local): Running local shell script: /var/folders/3k/2gb5ct4s7cncr52_jh2kz6cw0000gq/T/packer-shell201696062 ==> null.example1 (shell-local): Running local shell script: /var/folders/3k/2gb5ct4s7cncr52_jh2kz6cw0000gq/T/packer-shell494781572 null.example1 (shell-local): second post-processor Build 'null.example1' finished after 61 milliseconds 432 microseconds. null.example2 (shell-local): first post-processor Build 'null.example2' finished after 111 milliseconds 678 microseconds. ==> Wait completed after 111 milliseconds 714 microseconds ``` close #4895
super awesome! |
Hello there, thanks for trying this out @vishalbasra !! Just for the record, this will only work for HCL2 templates ! 🙂. |
packer validate template.json
The text was updated successfully, but these errors were encountered: