smalderma
2013-Nov-18 16:50 UTC
[Puppet Users] Is it possible to evaluate a string as a parameter name?
Hi, I''m looking to combine a couple of fact names with the value of a class parameter to create and lookup the resulting fact''s value. Is that possible? For example, my class will take the parameter "my_default_nic" from beyond. So I know that as long as $my_default_nic exists on the client, then so will facts like macaddress_<NIC>, netmask_<NIC>, and ipaddress_<NIC>. So I''m looking for a way to formulate those fact names and evaluate the result... Is this at all possible? Thanks for your thoughts! $my_default_nic = ''eth1''> $ip_method = ''static'' > $my_ip = ??????????? ### <- should end up looking > like the value of $::ipaddress_eth1 with out hardcoding eth1 > $my_netmask = ????????? ### <- <same idea as $my_ip> > > case $ip_method { > ''static'': { > network::static { $my_default_nic: > ensure => up, > ipaddress => $my_ip, > netmask => $my_netmask, > } > } > /(?i:dhcp|dynamic)'': { > network::dynamic { $my_default_nic: > ensure => up, > } > } > default: { > network::dynamic { $my_default_nic: > ensure => down, > } > } >-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/fc39aa90-27f9-44dc-b478-3a288f1111f2%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Nov-18 17:06 UTC
[Puppet Users] Re: Is it possible to evaluate a string as a parameter name?
On Monday, November 18, 2013 10:50:44 AM UTC-6, smalderma wrote:> > Hi, > I''m looking to combine a couple of fact names with the value of a class > parameter to create and lookup the resulting fact''s value. Is that > possible? For example, my class will take the parameter "my_default_nic" > from beyond. So I know that as long as $my_default_nic exists on the > client, then so will facts like macaddress_<NIC>, netmask_<NIC>, and > ipaddress_<NIC>. So I''m looking for a way to formulate those fact names > and evaluate the result... > > Is this at all possible? Thanks for your thoughts! >Something along these lines ought to do the trick: $my_interface = ''eth1'' $my_ip = inline_template("<%= scope.lookupvar(''::ipaddress_${my_interface}'') %>") John -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2a44bf90-9c37-4dcf-b905-959e0147954b%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Dan White
2013-Nov-18 17:50 UTC
Re: [Puppet Users] Is it possible to evaluate a string as a parameter name?
Here is what I did along the same lines: I made a custom fact that makes a fact of all user home directories: modules/users/lib/facter/user_home.rb require ''etc'' Etc.passwd { |user| Facter.add("home_#{user.name}") do setcode do user.dir end end } Then, in a dot-pp file, I did this: <blockquote> $home_fact = "home_${user_name}" $homedir = inline_template("<%= scope.lookupvar(''::${home_fact}'') %>") </blockquote> Going with this, you should be able to pass in your NIC label and then : <blockquote> $my_ip_setup = "ipaddress_${my_default_nic}" $my_ip = inline_template("<%= scope.lookupvar(''::${ my_ip_setup }'') %>") </blockquote> Hope this works for you. Let us all know, please. “Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.” Bill Waterson (Calvin & Hobbes) ----- Original Message ----- From: "smalderma" <salderman1@udayton.edu> To: puppet-users@googlegroups.com Sent: Monday, November 18, 2013 11:50:44 AM Subject: [Puppet Users] Is it possible to evaluate a string as a parameter name? Hi, I''m looking to combine a couple of fact names with the value of a class parameter to create and lookup the resulting fact''s value. Is that possible? For example, my class will take the parameter "my_default_nic" from beyond. So I know that as long as $my_default_nic exists on the client, then so will facts like macaddress_<NIC>, netmask_<NIC>, and ipaddress_<NIC>. So I''m looking for a way to formulate those fact names and evaluate the result... Is this at all possible? Thanks for your thoughts! <blockquote> $my_default_nic = ''eth1'' $ip_method = ''static'' $my_ip = ??????????? ### <- should end up looking like the value of $::ipaddress_eth1 with out hardcoding eth1 $my_netmask = ????????? ### <- <same idea as $my_ip> case $ip_method { ''static'': { network::static { $my_default_nic: ensure => up, ipaddress => $my_ip, netmask => $my_netmask, } } /(?i:dhcp|dynamic)'': { network::dynamic { $my_default_nic: ensure => up, } } default: { network::dynamic { $my_default_nic: ensure => down, } } </blockquote> -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/fc39aa90-27f9-44dc-b478-3a288f1111f2%40googlegroups.com . For more options, visit https://groups.google.com/groups/opt_out . -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/546661769.4605406.1384797032378.JavaMail.root%40sz0126a.westchester.pa.mail.comcast.net. For more options, visit https://groups.google.com/groups/opt_out.
smalderma
2013-Nov-18 18:03 UTC
Re: [Puppet Users] Is it possible to evaluate a string as a parameter name?
Thanks guys! That was simpler than I thought. I had not had an reason to dive into an inline template before, so it was a feature that I''ve read about, but not leveraged. I ended up applying John''s method of using an inline template for the ip, mac, and netmask. The inline template seems to do the trick! On Monday, November 18, 2013 12:50:32 PM UTC-5, Ygor wrote:> > Here is what I did along the same lines: > > I made a custom fact that makes a fact of all user home directories: > > modules/users/lib/facter/user_home.rb > require ''etc'' > > Etc.passwd { |user| > > Facter.add("home_#{user.name}") do > setcode do > user.dir > end > end > > } > > Then, in a dot-pp file, I did this: > > $home_fact = "home_${user_name}" > $homedir = inline_template("<%= scope.lookupvar(''::${home_fact}'') %>") > > Going with this, you should be able to pass in your NIC label and then : > > $my_ip_setup = "ipaddress_${my_default_nic}" > $my_ip = inline_template("<%= scope.lookupvar(''::${my_ip_setup}'') %>") > > Hope this works for you. Let us all know, please. > > “Sometimes I think the surest sign that intelligent life exists elsewhere > in the universe is that none of it has tried to contact us.” > Bill Waterson (Calvin & Hobbes) > > ------------------------------ > *From: *"smalderma" <salde...@udayton.edu <javascript:>> > *To: *puppet...@googlegroups.com <javascript:> > *Sent: *Monday, November 18, 2013 11:50:44 AM > *Subject: *[Puppet Users] Is it possible to evaluate a string as a > parameter name? > > Hi, > I''m looking to combine a couple of fact names with the value of a class > parameter to create and lookup the resulting fact''s value. Is that > possible? For example, my class will take the parameter "my_default_nic" > from beyond. So I know that as long as $my_default_nic exists on the > client, then so will facts like macaddress_<NIC>, netmask_<NIC>, and > ipaddress_<NIC>. So I''m looking for a way to formulate those fact names > and evaluate the result... > > Is this at all possible? Thanks for your thoughts! > > $my_default_nic = ''eth1'' >> $ip_method = ''static'' >> $my_ip = ??????????? ### <- should end up >> looking like the value of $::ipaddress_eth1 with out hardcoding eth1 >> $my_netmask = ????????? ### <- <same idea as $my_ip> >> >> case $ip_method { >> ''static'': { >> network::static { $my_default_nic: >> ensure => up, >> ipaddress => $my_ip, >> netmask => $my_netmask, >> } >> } >> /(?i:dhcp|dynamic)'': { >> network::dynamic { $my_default_nic: >> ensure => up, >> } >> } >> default: { >> network::dynamic { $my_default_nic: >> ensure => down, >> } >> } >> > -- > 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 <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/fc39aa90-27f9-44dc-b478-3a288f1111f2%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. >-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/ed82b03a-659c-48b5-a6b0-d92f093b100c%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.