Question about Packer variables passed via JSON

355 views
Skip to first unread message

andrew...@teamaol.com

unread,
May 17, 2017, 4:44:46 PM5/17/17
to Packer
I've been using Packer in the context of a Jenkinsfile (using the Pipeline plugin for Jenkins) with success.  The only problem is the need to write a JSON file to the local file system that can be passed to Packer.

Is there any sort of functionality that would allow me to execute Packer from a script, and pass a "JSON file", but via memory instead of a local file?

To put more context to the question, in the Jenkinsfile, the call currently looks something like this:

sh "packer build -var-file=variables.json packer.json"

...where the script is executing Packer via shell and is reading a local file that contains the JSON variables.

What I would like to be able to do is along the lines of:

def json_var = unimportant_function_that_generates_json()
sh
"packer build -var-file=${json_var} packer.json"

...where a variable is created in the script containing JSON, and the shell call to packer can be passed the variable.

Is anything like this possible? If not, are there any plans in the future to implement a feature similar to this?

Once again we're huge fans of Hashicorp's open source products here at AOL, keep up the good work!!!

Andrew

Matthew Hooker

unread,
May 17, 2017, 4:53:46 PM5/17/17
to Packer
Hi Andrew,

Glad to hear our tools are working out for you.

We don't allow you to pass an entire varfile in from the command line, but you can use -var to pass each variable. For example, you could generate a long list of `-var 'x=y' -var 'a=b'` etc and pass that in.

Hopefully that works for you.

--Matt

--
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/0e6eb23e-5e79-46b7-9521-7919b03ba586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rickard von Essen

unread,
May 18, 2017, 1:01:29 AM5/18/17
to packe...@googlegroups.com
And you can use process substitution:
packer build -var-fil=<(var_fn) template.json


/ Rickard 

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CAEpfdnz_d%2B0XyosP9k3fY6KejfyS7Y91HL8KrR4nBrg8P-Ld7w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages