Skip to content
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

Comments in Packer JSON Files #7544

Closed
vikas027 opened this issue Apr 21, 2019 · 5 comments
Closed

Comments in Packer JSON Files #7544

vikas027 opened this issue Apr 21, 2019 · 5 comments
Labels
config-2.0 core Core components of Packer enhancement

Comments

@vikas027
Copy link

Prior to Packer v1.4.0, I was able to use a multiline comment by adding a _description in the root level key.

  "_description": [
    "xxxx",
    "yyyy",
    "zzz"
  ],

Now, in Packer v1.4.0 we need to use _comment as shown here.

This is fine but it was actually better to use an array rather than a string to store some information of the image along with tracking numbers, etc

Can you please take this as a feature request?

@vikas027 vikas027 changed the title Comments in Template Comments in Packer JSON Files Apr 22, 2019
@SwampDragons
Copy link
Contributor

This is probably going to be rendered unnecessary when we switch to using HCL2 templates later this year, as they allow comments. As a workaround in the meantime, you can either stick to v1.3.5 or you can use jq to remove the "_description" from your packer template as part of your wrapping script.

For example:
jq 'del(._description)' commented_template.json

will print your template without the _description field to stdout.

I'll leave this issue open for now in case a community member wants to work on it, but the HashiCorp maintainers will probably not work on it.

@SwampDragons
Copy link
Contributor

This will be closed in #1768

@SwampDragons SwampDragons added core Core components of Packer enhancement config-2.0 labels Apr 22, 2019
@SwampDragons
Copy link
Contributor

I've added a documentation page that explains how to use jq to strip comments from docs, which will provide you with a workaround until we complete the HCL2 work. you can see it here: #7547

@dragon788
Copy link
Contributor

dragon788 commented Mar 28, 2020

I had a case where I had a REALLY long boot_command array, and I wanted to add comments to it, but with the type == 'object' I ended up having to wrap my comments within the array to make them objects (otherwise jq failed to find them), but then when it removed them it left the empty braces causing packer validate to fail. I extended the command slightly to run another filter and find these empty "objects" and remove them.

jq 'walk(if type == "object" then del(._comment) else . end) | del(.. | select(length == 0))' commented_template.json > clean_template.json ; packer validate clean_template.json && packer build clean_template.json

@ghost
Copy link

ghost commented Mar 29, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
config-2.0 core Core components of Packer enhancement
Projects
None yet
Development

No branches or pull requests

3 participants