-
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
templating meta issue #4530
Comments
if packer was written in python, the answer would be to use jinja2, which is an extremely powerful and easy-to-use templating language. Looks like someone tried a go port of it a couple years ago: https://github.com/jmoiron/jigo |
Some usecases to consider. Right now, I have a colleague who made a JS program to generate all of his packer configs, but the logic in that JS script is fairly straight-forward, and would be nice to simply keep all of that in one place. He also needs a separate JS script for each target json file, which is a maintenance headache. I find myself in situations where my json file could benefit from comments so that others can understand it better. Another thing I find myself doing is copying-n-pasting file upload provisioner entries which could easily be solved with a jinja for-loop construct. A possible problem with jinja2 templating of JSON files is the trailing comma problem with JSON. The templating would have to be smart enough to know whether or not a comma is needed (perhaps it would make sense to switch to YAML?). |
Another use case: passing packer variables (like builder_type, ...) to scripts in autounattend (windows) or kickstart/preseed (linux). E.g.: vsphere-iso builder uses vmware tools to get IP and go next "Waiting for IP" step. Having builder_type variable (or something like provisioning phase PACKER_BUILDER_TYPE env variable) allow to use more generic script switching to step installing vmware tools at build time, avoiding code duplication. I think having variables at earlier stages allow more flexibility and DRY code. |
I think that's really strange to not allow templating on cloud-config files where it's already supported on Terraform. |
@Dr-Shadow thanks for the update here. Sounds like you were able to figure things out. But your comment on the documentation not being clear enough is concerning to me. If it is not clear to you, chances are it might not be clear to others. Please feel free to open a PR with you suggested changes. We rely heavily on our docs and any help to improve them is very much appreciated. Cheers! |
Hi @mwhooker, Packer 1.7 supports the function What is missing is a way of creating files on the destination using a templated content (the result of the Terraform has a file provisioner https://www.terraform.io/docs/language/resources/provisioners/file.html that is very similar to Packer. See the way Terraform supports a Packer does not support such field. All we would need is to add that same
Just adding that Thanks. |
Hey @michelzanini, I think that is a good idea ! Thanks for suggesting 🙂 . Would you have the time to implement this feature ? |
@azr Unfortunately, at the moment I am really busy and won't have the time. |
Hey @michelzanini, it was quicker than I though, and so I opened a new PR to get a new The original issues of this PRs all have been addressed and so given that #11209 is on its way, I think it's okay to close this issue here. Please open a new issue if you have another feature or bug ! 🙂 Thanks everyone ! |
Thank you! |
@azr this is not super clear to me, does this mean that there will be a way to dynamically generate the contents of floppy_files, cd_files, etc now? Looking at the PR and the file provisioner it doesn't look that way, which seems to me to be a part of this issue? I really need to be able to use templatefile with floppy_files for windows builds, because autounattend.xml has to be passed in via floppy_files. |
@ekristen , the change is to get the file provisioner a new Other properties in other builders, such as |
@michelzanini that is what I thought, to my knowledge the file provisioner is only in the context of the VM like all other provisioners, copying content to the VM. This issue was for templating in general, the PR fixes or adds support in a very narrow scope. I would suggest this issue gets re-opened until the other areas that are lacking support are addressed. |
I would recommend that would be better to open another ticket just for |
Thanks for opening a new issue ! I just want to clarify that we can use the Adding a |
Just to note, cd_content doens't work in the vmware builder in the current release (it does in other builders, and vmware is fixed on the main branch per hashicorp/packer-plugin-vmware#30). Though there's a few more lingering bugs in hashicorp/packer-plugin-vmware#31. |
Issues about wanting some kind of templating are opened frequently. This would be replacing variables inside static files with information from packer either during the file provisioner or inside floppy_files or the http_server
Here are some examples:
I don't believe packer should be in the business of providing templating, as it's out of scope of packer in my opinion. However, it does seem to be requested often.
I'd like to discuss here possible solutions, but right now I don't have any.
The text was updated successfully, but these errors were encountered: