Is there a way to set environment variables that are valid for all provisioner steps?

1,507 views
Skip to first unread message

Alexander Lehmann

unread,
Jul 7, 2017, 6:56:03 AM7/7/17
to Packer
I am currently building vmware and virtualbox images with packer in the corporate environment (firewalled network) on my local machine, which requires a http/https proxy setting for any internet repo like yum, maven, ansible galaxy etc.

I have currently solved that by setting the env variables in each step (shell scripts, ansible command etc), I wonder if there is a way to set this for all commands that are run in the provisioners.


Rickard von Essen

unread,
Jul 7, 2017, 7:15:27 AM7/7/17
to packe...@googlegroups.com
No, there is no such option. But for everything that executes on the VM (guest) setting these in /etc/profiles.d/proxy.sh or ~/.bashrc etc should work. 

But not that ansible (remote) makes a point of not bringing over any environment variables. 

On Jul 7, 2017 12:56, "Alexander Lehmann" <alex...@gmail.com> wrote:
I am currently building vmware and virtualbox images with packer in the corporate environment (firewalled network) on my local machine, which requires a http/https proxy setting for any internet repo like yum, maven, ansible galaxy etc.

I have currently solved that by setting the env variables in each step (shell scripts, ansible command etc), I wonder if there is a way to set this for all commands that are run in the provisioners.


--
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/48745a06-5eaa-4c41-8fbf-d2d21ef599b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alvaro Miranda Aguilera

unread,
Jul 7, 2017, 8:23:23 AM7/7/17
to packe...@googlegroups.com
I personally do this trick.

I always copy a file called proxy.env and first line of the scripts is source the file.

If I am on a environment that requires proxy, just put in the file the information.
if I am on environment that doesn't require proxy, have an empty file.

Not sure for ansible

On Fri, Jul 7, 2017 at 12:56 PM, Alexander Lehmann <alex...@gmail.com> wrote:
I am currently building vmware and virtualbox images with packer in the corporate environment (firewalled network) on my local machine, which requires a http/https proxy setting for any internet repo like yum, maven, ansible galaxy etc.

I have currently solved that by setting the env variables in each step (shell scripts, ansible command etc), I wonder if there is a way to set this for all commands that are run in the provisioners.


--
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/48745a06-5eaa-4c41-8fbf-d2d21ef599b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Alexander Lehmann

unread,
Jul 8, 2017, 4:52:39 AM7/8/17
to Packer
Thanks for the tip, that works quite well (and reduced the places in the files that have the config from about 6 to 2 times, but I may get down to a single config variable)

I have figured out the ansible setting of the environment, so I just add that in case anybody finds this thread later via google.

Setting the proxy in profile.d or by sourcing a file will set the environment for the ansible-playbook command locally, to pass it the tasks that are run by ansible, add the following in yaml file:

- hosts: xxx

  roles
:
     
- xxx
     
...

  environment
:
    http_proxy
: "{{ lookup('env', 'http_proxy') }}"
    https_proxy
: "{{ lookup('env', 'https_proxy') }}"

The lookup function will not fail if the variable is not set so that should work with unset proxy env as well.


On Friday, July 7, 2017 at 2:23:23 PM UTC+2, Alvaro Miranda Aguilera wrote:
I personally do this trick.

I always copy a file called proxy.env and first line of the scripts is source the file.

If I am on a environment that requires proxy, just put in the file the information.
if I am on environment that doesn't require proxy, have an empty file.

Not sure for ansible
On Fri, Jul 7, 2017 at 12:56 PM, Alexander Lehmann <alex...@gmail.com> wrote:
I am currently building vmware and virtualbox images with packer in the corporate environment (firewalled network) on my local machine, which requires a http/https proxy setting for any internet repo like yum, maven, ansible galaxy etc.

I have currently solved that by setting the env variables in each step (shell scripts, ansible command etc), I wonder if there is a way to set this for all commands that are run in the provisioners.


--
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.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages