How do you escape a comma in a user variable?

31 views
Skip to first unread message

Todd Foley

unread,
Mar 13, 2019, 7:39:30 PM3/13/19
to Packer
How do you escape a comma in a user variable?

This breaks the functionality of the build. this example is based off the defined example: https://packer.io/docs/builders/docker.html#run_command
The only difference is this is going through a user variable, which breaks because the parsing has no way to escape the comma that has to be ignored. 

{
"variables": {
"changes": "CMD [\"nginx\", \"-g\", \"daemon off;\"]"
},

"builders": [
{
"type": "docker",
"image": "ubuntu:16.04",
"run_command": ["-d", "{{.Image}}"],
"changes": "{{ user `changes`}}",
"commit": true
}
],
"post-processors": [
[
{
"type": "docker-tag",
"repository": "my/ubuntu",
"tag": "16.04"
}
]
]
}

Rickard von Essen

unread,
Mar 14, 2019, 12:48:51 AM3/14/19
to packe...@googlegroups.com
You can't. 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/92180783-e0be-4324-86be-fcee97018201%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Todd Foley

unread,
Mar 14, 2019, 12:44:59 PM3/14/19
to Packer
Okay, i'll create a single template for each build; sounds like we need to write a tool that generates the template from a script to get around this. Any chance for this to be a feature request the team might take up? 

Rickard von Essen

unread,
Mar 14, 2019, 4:45:32 PM3/14/19
to packe...@googlegroups.com
This is hard to fix in a non breaking way and I think it will nut be fixed in the short term. Hopefully by the end of the year Packer uses HCL2 and that will fix this problem.

This is very easily handled with jq.
$ echo '{ "a": "", "b": "X" }' | jq '.a=[ 1, 2, 3 ]'
{
  "a": [
    1,
    2,
    3
  ],
  "b": "X"
}


Reply all
Reply to author
Forward
0 new messages