Search code examples
puppetinterpolationerbfacter

Puppet pass a fact into a double-quoted line of code in an ERB file


I'm sure the answer to this is straightforward, but I can't find out how to do this. I have a line in my erb template file that needs to write exactly as-is into a server's config file (for OpenVPN):

push "dhcp-option DNS 192.16.23.12"

I need to change this so that the ip address gets looked up from the facter listing on the server, rather than having it hard-coded, as this conf file needs to be used on different servers now. The fact holding this ip address is "ipaddress_tun0". I've tried putting it into my line, thus:

push "dhcp-option DNS <%= @ipaddress_tun0 %>"

.. but the fact doesn't get interpolated properly, presumably because of the double quotes. Unfortunately the double quotes are needed as a literal part of the line in the conf file, so they have to be there (single quotes don't work). Can anyone advise how I can get this line to look up and insert the value of ipaddress_tun0, please?


Solution

  • push "dhcp-option DNS <%= scope.lookupvar('ipaddress_tun0') %>"   
    

    was what was needed, as my fact was out of the current scope.