OlliesDad@googlemail.com
2013-Jul-11 09:15 UTC
[Puppet Users] "Looping" around a custom fact list
Hello, We have a custom fact to show all kernels installed which appends a count. i.e. installed_kernel0 => 2.6.18-274.3.1.el5 installed_kernel1 => 2.6.18-308.16.1.el5 installed_kernel2 => 2.6.18-194.11.4.el5 What I want Puppet to do is to "loop" through this list of potential kernels and install a specific driver package for all possibilities. i.e. mykod-${installed_kernelX} Is this even possible without a custom provider ? Thanks Paul -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Paul Tötterman
2013-Jul-11 09:17 UTC
[Puppet Users] Re: "Looping" around a custom fact list
> What I want Puppet to do is to "loop" through this list of potential > kernels and install a specific driver package for all possibilities. > Is this even possible without a custom provider ? >I doubt it, unless you also export a installed_kernel_count => 3 fact. Cheers, Paul -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
OlliesDad@googlemail.com
2013-Jul-11 09:21 UTC
[Puppet Users] Re: "Looping" around a custom fact list
On Thursday, July 11, 2013 10:17:47 AM UTC+1, Paul Tötterman wrote:> > > What I want Puppet to do is to "loop" through this list of potential >> kernels and install a specific driver package for all possibilities. >> Is this even possible without a custom provider ? >> > > I doubt it, unless you also export a installed_kernel_count => 3 fact. > >Thanks as luck we have it we do as part of the custom fact installed_kernel_count => 3 -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, July 11, 2013 4:21:18 AM UTC-5, Olli...@googlemail.com wrote:> > > > On Thursday, July 11, 2013 10:17:47 AM UTC+1, Paul Tötterman wrote: >> >> >> What I want Puppet to do is to "loop" through this list of potential >>> kernels and install a specific driver package for all possibilities. >>> Is this even possible without a custom provider ? >>> >> >> I doubt it, unless you also export a installed_kernel_count => 3 fact. >> >> > Thanks as luck we have it we do as part of the custom fact > > installed_kernel_count => 3 > >Step one: create an array of the desired resource titles, of some other suitable identifiers of the target resource, or of something you can transform into the same. To do this without writing a custom function, you probably need to create a list of the titles in string form via inline_template(), then split() it. Step two: use the array of titles to declare the desired resources. Details depend on your exact needs: maybe you can just declare packages, but you can also declare instances of a defined type. That might come together something like this: class site::kernel_dirvers { $kernel_fact_stem = ''installed_kernel'' $kernel_list = inline_template("<%= (0...@installed_kernel_count.to_i).collect{|n| @kernel_fact_stem + n.to_s}.join('','') %>") $kernels = split($kernel_list, '','') site::my_kernel_driver { $kernels: } } define site::my_kernel_driver () { $driver_title = "mykod-${title}" # ensure the selected driver present, # maybe something like this: package { $driver_title: ensure => latest } } 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, July 11, 2013 8:41:03 AM UTC-5,I wrote:> > > $kernel_fact_stem = ''installed_kernel'' > $kernel_list = inline_template("<%= > (0...@installed_kernel_count.to_i).collect{|n| @kernel_fact_stem + > n.to_s}.join('','') %>") > >Sorry, I think I''ve buggered that up a bit. It should be more like this: $kernel_list = inline_template("<%= (0...@installed_kernel_count.to_i).collect{|n| eval(''@'' + @kernel_fact_stem + n.to_s)}.join('','') %>") The idea is that you construct the name of the desired Puppet variable via Ruby code, then retrieve the associated value (the original version would have returned the variable names instead of their values). You could also use a similar approach based on scope.lookupvar() if you dislike eval(). 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
OlliesDad@googlemail.com
2013-Jul-16 09:13 UTC
[Puppet Users] Re: "Looping" around a custom fact list
On Thursday, July 11, 2013 11:21:12 PM UTC+1, jcbollinger wrote:> > > > On Thursday, July 11, 2013 8:41:03 AM UTC-5,I wrote: >> >> >> $kernel_fact_stem = ''installed_kernel'' >> $kernel_list = inline_template("<%= >> (0...@installed_kernel_count.to_i).collect{|n| @kernel_fact_stem + >> n.to_s}.join('','') %>") >> >> > Sorry, I think I''ve buggered that up a bit. It should be more like this: > > $kernel_list = inline_template("<%= > (0...@installed_kernel_count.to_i).collect{|n| eval(''@'' + @kernel_fact_stem > + n.to_s)}.join('','') %>") > > The idea is that you construct the name of the desired Puppet variable via > Ruby code, then retrieve the associated value (the original version would > have returned the variable names instead of their values). You could also > use a similar approach based on scope.lookupvar() if you dislike eval(). > > > Thanks that works. Now to get them into an array so I can spin themthrough a define. Appreciate the help -- 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 post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.