I''m having a problem with variable interpolation that I haven''t found a good solution to. I want to use a variable as part of the name of a fact, but the interpolation doesn''t work as expected. I''ve allowed for passing the mac address into my define() but if it''s not provided I want to look it up via facter. if "$macaddress_${name}" { $final_hwaddr = "$macaddress_${name}" } I want Puppet to look up the value of macaddress_eth0 or whatever, but instead it returns the value of $name. How can I get the appropriate value? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Mon, May 23, 2011 at 3:51 PM, Aaron Grewell <aaron.grewell@gmail.com> wrote:> I''m having a problem with variable interpolation that I haven''t found a good > solution to. I want to use a variable as part of the name of a fact, but > the interpolation doesn''t work as expected. I''ve allowed for passing the > mac address into my define() but if it''s not provided I want to look it up > via facter. > > if "$macaddress_${name}" { > $final_hwaddr = "$macaddress_${name}" > } > > I want Puppet to look up the value of macaddress_eth0 or whatever, but > instead it returns the value of $name. How can I get the appropriate value?Should be a function instead of inline_template: $myvar = "macaddress_${name}" $hwaddr = inline_template("<%= scope.lookupvar(myvar) %>") Nan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thanks Nan, until they make a function out of that I''ll keep the template in my cheat sheet. On Mon, May 23, 2011 at 4:53 PM, Nan Liu <nan@puppetlabs.com> wrote:> On Mon, May 23, 2011 at 3:51 PM, Aaron Grewell <aaron.grewell@gmail.com> > wrote: > > I''m having a problem with variable interpolation that I haven''t found a > good > > solution to. I want to use a variable as part of the name of a fact, but > > the interpolation doesn''t work as expected. I''ve allowed for passing the > > mac address into my define() but if it''s not provided I want to look it > up > > via facter. > > > > if "$macaddress_${name}" { > > $final_hwaddr = "$macaddress_${name}" > > } > > > > I want Puppet to look up the value of macaddress_eth0 or whatever, but > > instead it returns the value of $name. How can I get the appropriate > value? > > Should be a function instead of inline_template: > > $myvar = "macaddress_${name}" > $hwaddr = inline_template("<%= scope.lookupvar(myvar) %>") > > Nan > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.