I am trying to setup a proxy before the wget call is issued:
file { "/etc/environment":
content => inline_template("
http_proxy=http://10.0.12.13:8080
https_proxy=http://10.0.12.13:8080")
}
The problem is that I have to restart the Puppet's session in order to load the environment properly.
I have also tried to export the variables in the exec statement:
exec { "proxy-export-vars":
provider => "shell",
command => "export http_proxy=http://10.0.12.13:8080 && export https_proxy=http://10.0.12.13:8080",
}
The question is - how to load the environment settings without restarting the session and the puppet apply process?
The WGET puppet plugin is using the top scope variables searching for proxy settings. So the trick is to define these variables in the top scope, that is before the node definition. The complete working code:
$http_proxy = "http://10.0.12.13:8080"
$https_proxy = "http://10.0.12.13:8080"
node 'machine' {
# ...
}
And from now on the WGET puppet plugin is going to fetch resources with these proxy settings.
The easiest way to set an environment variable for a single exec resource is to use the environment attribute. See the documentation here. For example:
exec {'fetch something':
environment => [
'http_proxy=http://10.0.12.13:8080',
'https_proxy=http://10.0.12.13:8080',
],
command => '/usr/bin/wget -o /tmp/myfile http://myserver/myfile',
}
Your second attempt...
exec { "proxy-export-vars":
provider => "shell",
command => "export http_proxy=http://10.0.12.13:8080 && export https_proxy=http://10.0.12.13:8080",
...would fail because (a) export is a shell built-in command, so
Puppet wouldn't be able to exec it since there is no corresponding
binary...and (b) even if it could, it wouldn't do what you want, because
setting an environment variable like that is not persistent -- it only
affects the current process and its children.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With