Packer: Variables inside vagrantfile_template of vagrant postprocessor not replaced

Created on 10 Sep 2020  ·  8Comments  ·  Source: hashicorp/packer

Overview of the Issue

Variables inside the file pointed by the vagrantfile_template are not replaced during box creation

Reproduction Steps

  • Add a docker provider
  • Add a vagrant post processor
  • Create a vagrantfile template with a variable inside for example config.vm.box = {{.Name}}
  • Run the build
  • Extract the vagrantfile from the box and see that variables are still there.

Packer version

1.6.2`

Simplified Packer Buildfile

{
"builders": [
{
"type": "docker",
"image": "ubuntu:latest",
"commit": "true",
"pull": "false",
"run_command": ["-d", "-i", "-t", "--entrypoint=/bin/bash", "--", "{{.Image}}"]
}
],

"post-processors":
[
{
"type": "vagrant",
"keep_input_artifact": true,
"vagrantfile_template": "Vagrantfile.template"
}
]
}

Operating system and Environment details

Ubuntu 20.04

Log Fragments and crash.log files

Unavailable

bug post-processovagrant track-internal

All 8 comments

Thanks for reaching out. We’ll take a look when we get a chance!

Hey there, I implemented a solution for this and you can test it with these binaries: https://app.circleci.com/pipelines/github/hashicorp/packer/7128/workflows/9d21e444-7712-4abc-ae89-5c13fae1ca94/jobs/80661/artifacts
To interpolate the build name you should use {{build_name}} or {{.BuildName}} instead of just {{.Name}}.
Here the docs for the template engine build_name

Great I'll do that !
Is it working with all the functions of the template engine !
My goal here is to retrieve the sha256 of the container produced by the build and use it in the d.image argument of the vagrant filen

I think with what we have right now you won't be able to do that. We could try to add a specific docker builder variable with such information, something like {{ build 'ImageSha256' }}, and then you use it in your template like the build name one.
Would that be helpful to you?

That would be super useful !

Soo, here are the binaries you can use to test the {{ build 'ImageSha256'}} variable
https://app.circleci.com/pipelines/github/hashicorp/packer/7139/workflows/26c1e714-77f7-4ded-abcd-36d5e89521d9/jobs/80812/artifacts
Let me know if works for you!

Ok that's working ! thanks !

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