nested variables

330 views
Skip to first unread message

sHaggY_caT

unread,
Dec 24, 2009, 4:33:24 AM12/24/09
to Puppet Users
Hi all!

I have quation: how i may use nested variables/facts? For example, I
have variable $iface. It's variable declared in node brakets, and, use
with defenition. iface may be eth0, eth1(Linux), em0, ...
<freebsd>, ...

is fact:

facter | grep eth0 | grep mac
macaddress_eth0 => 54:52:00:3D:CB:40

We don'nt know name of $iface in our module (to generate network
settings), how we may use nested variables/facts? Syntax:

$mac = ${$macaddress_${iface}}

Does'nt work.

In documentation i did'nt find answer for my quation...

Mike Pountney

unread,
Dec 24, 2009, 6:09:45 AM12/24/09
to puppet...@googlegroups.com
Have a look at the generate() and inline_template() functions, one of
which should provide you with a workaround to your problem. There may
be a more elegant solution though.

> --
>
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en
> .
>
>

sHaggY_caT

unread,
Dec 25, 2009, 11:55:07 AM12/25/09
to Puppet Users
Thank you very much for answer.

Do you may print simple working example?

I don't find it in documentation, sorry

On 24 дек, 11:09, Mike Pountney <mike.pount...@gmail.com> wrote:
> Have a look at the generate() and inline_template() functions, one of  
> which should provide you with a workaround to your problem. There may  
> be a more elegant solution though.
>

Scott Smith

unread,
Dec 25, 2009, 8:18:12 PM12/25/09
to puppet...@googlegroups.com
sHaggY_caT wrote:
> Thank you very much for answer.
>
> Do you may print simple working example?
>

$ifaces = split($interfaces, ',')

define do::it {
$tpl = "<% if has_variable?(\"ipaddress_$name\") -%>
The IP address for $name is: <%= ipaddress_$name %>
<% end -%>
"

notice(inline_template($tpl))
}

do::it { $ifaces: }

-scott

sHaggY_caT

unread,
Dec 26, 2009, 3:24:58 AM12/26/09
to Puppet Users
Thank's, Scott :)

Happy New Year!

Silviu Paragina

unread,
Dec 26, 2009, 7:06:09 AM12/26/09
to puppet...@googlegroups.com
On 24.12.2009 11:33, sHaggY_caT wrote:
> Hi all!
>
> I have quation: how i may use nested variables/facts? For example, I
> have variable $iface. It's variable declared in node brakets, and, use
> with defenition. iface may be eth0, eth1(Linux), em0, ...
> <freebsd>, ...
>
> is fact:
>
> facter | grep eth0 | grep mac
> macaddress_eth0 => 54:52:00:3D:CB:40
>
> We don'nt know name of $iface in our module (to generate network
> settings), how we may use nested variables/facts? Syntax:
>
> $mac = ${$macaddress_${iface}}
>
Shouldn't this be ${macaddress_${iface}} ?

Silviu

> Does'nt work.
>
> In documentation i did'nt find answer for my quation...
>

Scott Smith

unread,
Dec 26, 2009, 1:10:45 PM12/26/09
to puppet...@googlegroups.com
Silviu Paragina wrote:
>> $mac = ${$macaddress_${iface}}
>>
> Shouldn't this be ${macaddress_${iface}} ?
>

Have you tried that? Doesn't work for me in 0.25.1.

-scott

Silviu Paragina

unread,
Dec 26, 2009, 2:10:59 PM12/26/09
to puppet...@googlegroups.com
Not really, tested it now, and you are right, but there was an extra $
in there, sorry :">


Silviu
> -scott

Reply all
Reply to author
Forward
0 new messages