How to solve problem with many variables in mind?

22 views
Skip to first unread message

Deking

unread,
Mar 14, 2019, 9:57:52 AM3/14/19
to Packer
As you can see here my whole set up: https://groups.google.com/forum/#!topic/packer-tool/WQEXIut-ibI


The issue with this is that i have too many variables (lets say 40) and packer json would be too crowded.



{
"type": "shell",
"script": "./example.sh",
"environment_vars": [
"AWS_ACCESS_KEY={{user `script_aws_access`}}",
"AWS_SECRET_ACCESS_KEY={{user `script_aws_secret_access`}}",
"VPN_01_PUBLIC_IP={{user `vpn_01_public_ip`}}",
"VPN_01_PRIVATE_IP={{user `vpn_01_private_ip`}}"
5
6
7
8
9
10
etc
],
"pause_before": "10s"
}

Is there a way to hold non sensitive variables in separate file?
I was thinking something like this:

{
"type": "shell",
"script": "./example.sh",
"use_env_var_file": true,
"execute_command": "chmod +x {{ .Path }}; {{ .EnvVarFile }} sudo -E sh '{{ .Path }}'",
"environment_vars": [
"AWS_ACCESS_KEY={{user `script_aws_access`}}",
"AWS_SECRET_ACCESS_KEY={{user `script_aws_secret_access`}}",
"pause_before": "10s"
}

So the point is to use "environment_vars" for AWS keys and other secrets, and VarFile for other non sensitive values.
1. How this can be achieved? 
2 . Where we can set .EnvVarFile variable? How packer knows the path to the Var file?
3. .Path ( in this case packer knows where is example.sh, right? 

Megan Marsh

unread,
Mar 14, 2019, 12:17:39 PM3/14/19
to packe...@googlegroups.com
There's no way to do this directly, but you can use the "file" provisioner to upload a VarFile, and then dot-source the file from within your shell script.
Reply all
Reply to author
Forward
0 new messages