Variables inside variables

32 views
Skip to first unread message

Jonathan Gazeley

unread,
Mar 31, 2016, 6:04:45 AM3/31/16
to puppet...@googlegroups.com
Hi folks,

Short version:

I want to use a variable inside a variable to access a fact. Is this
possible?

Long version:

Facter provides facts $::ipaddress and $::netmask which figure out which
is your primary interface and then return values like $::ipaddress_eth0
and $::netmask_eth0. However there is not a $::network fact to reflect
$::network_eth0.

I have a custom fact $::gateway_dev which returns the name of the
primary interface. Is it possible to access the variable like
${::network_${::gateway_dev}} ?

Thanks,
Jonathan

--
Jonathan Gazeley
Senior Systems Administrator
IT Services
University of Bristol

Daniel Sung

unread,
Mar 31, 2016, 6:21:23 AM3/31/16
to Puppet Users
I achieve this by using the getvar function in stdlib. For example:

getvar("::network_${::gateway_dev}")

Regards,
Daniel

Jonathan Gazeley

unread,
Mar 31, 2016, 6:44:47 AM3/31/16
to puppet...@googlegroups.com
Great, thanks!
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/44689bb5-7eff-4a03-ac80-095c5948eaaa%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/44689bb5-7eff-4a03-ac80-095c5948eaaa%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages