<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><div><br></div><div><br></div><div><br></div><div><br></div><div id="composer_signature"><div style="font-size:85%;color:#575757" dir="auto">Sent from my Galaxy Tab A (2016)</div></div><div style="font-size:100%;color:#000000"><!-- originalMessage --><div>-------- Original message --------</div><div>From: varnish-misc-request@varnish-cache.org </div><div>Date: 9/10/2019 12:38 PM (GMT+05:45) </div><div>To: varnish-misc@varnish-cache.org </div><div>Subject: varnish-misc Digest, Vol 160, Issue 3 </div><div><br></div></div>Send varnish-misc mailing list submissions to<br> varnish-misc@varnish-cache.org<br><br>To subscribe or unsubscribe via the World Wide Web, visit<br> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc<br>or, via email, send a message with subject or body 'help' to<br> varnish-misc-request@varnish-cache.org<br><br>You can reach the person managing the list at<br> varnish-misc-owner@varnish-cache.org<br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of varnish-misc digest..."<br><br><br>Today's Topics:<br><br> 1. Re: Environment variables in VCL (Bender, Charles)<br> 2. Re: Environment variables in VCL (Guillaume Quintard)<br> 3. Re: Environment variables in VCL (Poul-Henning Kamp)<br> 4. Re: Environment variables in VCL (Guillaume Quintard)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Tue, 10 Sep 2019 00:15:42 +0000<br>From: "Bender, Charles" <charles@beachcamera.com><br>To: Hugues Alary <hugues@betabrand.com>, varnish-misc<br> <varnish-misc@varnish-cache.org><br>Subject: Re: Environment variables in VCL<br>Message-ID: <DAF960C1-B889-4942-A60B-3FCC64695A8D@beachcamera.com><br>Content-Type: text/plain; charset="utf-8"<br><br>Looking at a VCL I use to set hostname and this seems to work-<br><br>sub vcl_deliver {<br> set resp.http.X-Cache-Node = server.hostname;<br>}<br><br>Maybe you can use in form of server.environmental_variable<br><br>From: varnish-misc <varnish-misc-bounces+charles=beachcamera.com@varnish-cache.org> on behalf of Hugues Alary <hugues@betabrand.com><br>Date: Monday, September 9, 2019 at 6:09 PM<br>To: varnish-misc <varnish-misc@varnish-cache.org><br>Subject: Environment variables in VCL<br><br>Hi there,<br><br>I'm using Varnish in a Kubernetes cluster and my configuration needs to use environment variables.<br><br>More specifically, I'm trying to declare a `backend` with a `.host` whose value is an environment variable.<br><br>backend b0 {<br> .host = "$ENVIRONMENT_VARIABLE_HOSTNAME";<br> .port = "80";<br> .connect_timeout = 300s;<br> .first_byte_timeout = 300s;<br> .between_bytes_timeout = 300s;<br>}<br><br>This doesn't work. It tried using the std.get_env() function but it doesn't work in this context.<br><br>Is there any way to use environment variables in VCL, or do I have to create a configuration template?<br><br>Thanks for your help,<br><br>Cheers,<br>-Hugues<br><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190910/672db2ce/attachment-0001.html><br><br>------------------------------<br><br>Message: 2<br>Date: Tue, 10 Sep 2019 07:38:44 +0200<br>From: Guillaume Quintard <guillaume@varnish-software.com><br>To: "Bender, Charles" <charles@beachcamera.com><br>Cc: Hugues Alary <hugues@betabrand.com>, varnish-misc<br> <varnish-misc@varnish-cache.org><br>Subject: Re: Environment variables in VCL<br>Message-ID:<br> <CAJ6ZYQy5RnBjfCs88re6-hMfsQvyuzbOkHoofQ_c+suQNRQjig@mail.gmail.com><br>Content-Type: text/plain; charset="utf-8"<br><br>Hi,<br><br>The trouble is that the backends are C structures created when you compile<br>the VCL, but std.getenv() is called when you use the compile VCL, so that<br>way too late.<br><br>I see two ways:<br>- use a dynamic backend vmod (like vmod_goto), allowing you to regularly<br>interrogate DNS a build an elastic director<br>- create a static backend point to you k8s proxy, and just set<br>req.http.host to whatever value you want.<br><br>The last one is two of course create a template, but remember that varnish<br>resolves domain names in static backend when it compiles the VCL, so the<br>resolved IP may not be right all the time.<br>-- <br>Guillaume Quintard<br><br><br>On Tue, Sep 10, 2019 at 2:17 AM Bender, Charles <charles@beachcamera.com><br>wrote:<br><br>> Looking at a VCL I use to set hostname and this seems to work-<br>><br>><br>><br>> sub vcl_deliver {<br>><br>> set resp.http.X-Cache-Node = server.hostname;<br>><br>> }<br>><br>><br>><br>> Maybe you can use in form of server.environmental_variable<br>><br>><br>><br>> *From: *varnish-misc <varnish-misc-bounces+charles=<br>> beachcamera.com@varnish-cache.org> on behalf of Hugues Alary <<br>> hugues@betabrand.com><br>> *Date: *Monday, September 9, 2019 at 6:09 PM<br>> *To: *varnish-misc <varnish-misc@varnish-cache.org><br>> *Subject: *Environment variables in VCL<br>><br>><br>><br>> Hi there,<br>><br>><br>><br>> I'm using Varnish in a Kubernetes cluster and my configuration needs to<br>> use environment variables.<br>><br>><br>><br>> More specifically, I'm trying to declare a `backend` with a `.host` whose<br>> value is an environment variable.<br>><br>><br>> backend b0 {<br>> .host = "*$ENVIRONMENT_VARIABLE_HOSTNAME*";<br>> .port = "80";<br>> .connect_timeout = 300s;<br>> .first_byte_timeout = 300s;<br>> .between_bytes_timeout = 300s;<br>><br>> }<br>><br>><br>><br>> This doesn't work. It tried using the std.get_env() function but it<br>> doesn't work in this context.<br>><br>><br>><br>> *Is there any way to use environment variables in VCL, or do I have to<br>> create a configuration template?*<br>><br>><br>><br>> Thanks for your help,<br>><br>><br>><br>> Cheers,<br>><br>> -Hugues<br>><br>><br>> _______________________________________________<br>> varnish-misc mailing list<br>> varnish-misc@varnish-cache.org<br>> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc<br>><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190910/15f9a551/attachment-0001.html><br><br>------------------------------<br><br>Message: 3<br>Date: Tue, 10 Sep 2019 06:44:45 +0000<br>From: "Poul-Henning Kamp" <phk@phk.freebsd.dk><br>To: Guillaume Quintard <guillaume@varnish-software.com><br>Cc: "Bender, Charles" <charles@beachcamera.com>, varnish-misc<br> <varnish-misc@varnish-cache.org><br>Subject: Re: Environment variables in VCL<br>Message-ID: <14936.1568097885@critter.freebsd.dk><br>Content-Type: text/plain; charset="us-ascii"<br><br>--------<br>In message <CAJ6ZYQy5RnBjfCs88re6-hMfsQvyuzbOkHoofQ_c+suQNRQjig@mail.gmail.com><br>, Guillaume Quintard writes:<br><br>>I see two ways:<br><br>There is a third way:<br><br>You can use:<br><br> include "somefile"<br><br>anywhere and everywhere in a VCL program.<br><br>Before you start your varnishd, do this in a shell script:<br><br> echo "\"$ENVIRONMENT_VARIABLE_HOSTNAME\"" > /somewhere/hostname.vcl<br><br>Then in VCL:<br><br> backend b0 {<br> .host = include "/somewhere/hostname.vcl" ;<br> .port 80<br> ...<br><br><br><br>-- <br>Poul-Henning Kamp | UNIX since Zilog Zeus 3.20<br>phk@FreeBSD.ORG | TCP/IP since RFC 956<br>FreeBSD committer | BSD since 4.3-tahoe <br>Never attribute to malice what can adequately be explained by incompetence.<br><br><br>------------------------------<br><br>Message: 4<br>Date: Tue, 10 Sep 2019 08:52:53 +0200<br>From: Guillaume Quintard <guillaume@varnish-software.com><br>To: Poul-Henning Kamp <phk@phk.freebsd.dk><br>Cc: "Bender, Charles" <charles@beachcamera.com>, varnish-misc<br> <varnish-misc@varnish-cache.org><br>Subject: Re: Environment variables in VCL<br>Message-ID:<br> <CAJ6ZYQzhdbagqWzVmBDbs7uOS+SY+0BNUCYaJn3fVpXBqkfDCQ@mail.gmail.com><br>Content-Type: text/plain; charset="utf-8"<br><br>True, but that amounts to template processing :-)<br><br>-- <br>Guillaume Quintard<br><br><br>On Tue, Sep 10, 2019 at 8:44 AM Poul-Henning Kamp <phk@phk.freebsd.dk><br>wrote:<br><br>> --------<br>> In message <<br>> CAJ6ZYQy5RnBjfCs88re6-hMfsQvyuzbOkHoofQ_c+suQNRQjig@mail.gmail.com><br>> , Guillaume Quintard writes:<br>><br>> >I see two ways:<br>><br>> There is a third way:<br>><br>> You can use:<br>><br>> include "somefile"<br>><br>> anywhere and everywhere in a VCL program.<br>><br>> Before you start your varnishd, do this in a shell script:<br>><br>> echo "\"$ENVIRONMENT_VARIABLE_HOSTNAME\"" > /somewhere/hostname.vcl<br>><br>> Then in VCL:<br>><br>> backend b0 {<br>> .host = include "/somewhere/hostname.vcl" ;<br>> .port 80<br>> ...<br>><br>><br>><br>> --<br>> Poul-Henning Kamp | UNIX since Zilog Zeus 3.20<br>> phk@FreeBSD.ORG | TCP/IP since RFC 956<br>> FreeBSD committer | BSD since 4.3-tahoe<br>> Never attribute to malice what can adequately be explained by incompetence.<br>><br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20190910/9d6ef430/attachment.html><br><br>------------------------------<br><br>Subject: Digest Footer<br><br>_______________________________________________<br>varnish-misc mailing list<br>varnish-misc@varnish-cache.org<br>https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc<br><br><br>------------------------------<br><br>End of varnish-misc Digest, Vol 160, Issue 3<br>********************************************<br></body></html>