Morning all I''m currently trying to work out a method to auto-generate a set of facts. These facts need to contain information about what database clones have been created using NetApp SnapManager for Oracle on a given Host... I need the fact to give the following information: clone_ACREPC11 => 10.10.160.1:/vol/SnapManager_20130307153440293_v_ACTEST11_oradata/q_ACTEST11_oradata ACREPC11 is an generated database SID that will change across clones, and the value is an auto-generated NFS export path... The export path is going to be grepped out of the fstab, which I can handle :D However there could be multiple clones on a given host, so ideally I want one fact file to generate all the required facts... Possible? Cheers Gavin -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On 08.03.2013 10:12, Gavin Williams wrote:> Morning all > > I''m currently trying to work out a method to auto-generate a set of facts. > These facts need to contain information about what database clones have > been created using NetApp SnapManager for Oracle on a given Host... > > I need the fact to give the following information: > clone_ACREPC11 => > 10.10.160.1:/vol/SnapManager_20130307153440293_v_ACTEST11_oradata/q_ACTEST11_oradata > > ACREPC11 is an generated database SID that will change across clones, > and the value is an auto-generated NFS export path... > The export path is going to be grepped out of the fstab, which I can > handle :D > > However there could be multiple clones on a given host, so ideally I > want one fact file to generate all the required facts... > > Possible?There are ipaddress_${ifname} facts, so I guess it''s possible. And that would also be the example I''D check out to see how it''s done ;-) Happy Hacking, D. -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Ok, looks like I wasn''t googling hard-enough :( Managed to find Nan Liu''s Puppetlabs blog post Facter Part 3: Caching and TTL <https://puppetlabs.com/blog/facter-part-3-caching-and-ttl/>, which showed how to generate multiple facter facts on the fly :) So after a bit of coding came up with: https://gist.github.com/fatmcgav/5115394#file-oracle_clones-rb Cheers Gav On Friday, 8 March 2013 09:12:55 UTC, Gavin Williams wrote:> > Morning all > > I''m currently trying to work out a method to auto-generate a set of facts. > These facts need to contain information about what database clones have > been created using NetApp SnapManager for Oracle on a given Host... > > I need the fact to give the following information: > clone_ACREPC11 => > 10.10.160.1:/vol/SnapManager_20130307153440293_v_ACTEST11_oradata/q_ACTEST11_oradata > > ACREPC11 is an generated database SID that will change across clones, and > the value is an auto-generated NFS export path... > The export path is going to be grepped out of the fstab, which I can > handle :D > > However there could be multiple clones on a given host, so ideally I want > one fact file to generate all the required facts... > > Possible? > > Cheers > Gavin >-- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Ok, next challenge now I''ve got these facts is how to get the values out of them in my Puppet manifests :S As it''s now an auto-generated name, I''ve got to work out a dynamic fact name, and then pull that value back... Have tried a few different code combos, however i''m not getting any luck :( Is this something that''s just not possible, or am I missing a trick? I''m hoping the latter... Cheers Gav On Friday, 8 March 2013 09:50:44 UTC, Gavin Williams wrote:> > Ok, looks like I wasn''t googling hard-enough :( > > Managed to find Nan Liu''s Puppetlabs blog post Facter Part 3: Caching and > TTL <https://puppetlabs.com/blog/facter-part-3-caching-and-ttl/>, which > showed how to generate multiple facter facts on the fly :) > > So after a bit of coding came up with: > https://gist.github.com/fatmcgav/5115394#file-oracle_clones-rb > > Cheers > Gav > > On Friday, 8 March 2013 09:12:55 UTC, Gavin Williams wrote: >> >> Morning all >> >> I''m currently trying to work out a method to auto-generate a set of >> facts. >> These facts need to contain information about what database clones have >> been created using NetApp SnapManager for Oracle on a given Host... >> >> I need the fact to give the following information: >> clone_ACREPC11 => >> 10.10.160.1:/vol/SnapManager_20130307153440293_v_ACTEST11_oradata/q_ACTEST11_oradata >> >> ACREPC11 is an generated database SID that will change across clones, and >> the value is an auto-generated NFS export path... >> The export path is going to be grepped out of the fstab, which I can >> handle :D >> >> However there could be multiple clones on a given host, so ideally I want >> one fact file to generate all the required facts... >> >> Possible? >> >> Cheers >> Gavin >> >-- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Google to the rescue again... Stumbled across this link: http://serverfault.com/questions/325591/puppet-checking-sets-of-variables This suggested using the "inline_template" function to do an erb evaluation of my variable... So changed the following line: # Get export path fact for db $oracle_sid_lower = downcase($oracle_sid) $fact_name = "clone_${oracle_sid_lower}" # Use an inline template to lookup dynamically generated fact name $export_line = inline_template(''<%= scope.lookupvar(fact_name) %>'') And hey-presto, it works... :D Cheers Gav On Friday, 8 March 2013 10:54:53 UTC, Gavin Williams wrote:> > Ok, next challenge now I''ve got these facts is how to get the values out > of them in my Puppet manifests :S > > As it''s now an auto-generated name, I''ve got to work out a dynamic fact > name, and then pull that value back... > > Have tried a few different code combos, however i''m not getting any luck > :( > > Is this something that''s just not possible, or am I missing a trick? I''m > hoping the latter... > > Cheers > Gav > > On Friday, 8 March 2013 09:50:44 UTC, Gavin Williams wrote: >> >> Ok, looks like I wasn''t googling hard-enough :( >> >> Managed to find Nan Liu''s Puppetlabs blog post Facter Part 3: Caching >> and TTL <https://puppetlabs.com/blog/facter-part-3-caching-and-ttl/>, >> which showed how to generate multiple facter facts on the fly :) >> >> So after a bit of coding came up with: >> https://gist.github.com/fatmcgav/5115394#file-oracle_clones-rb >> >> Cheers >> Gav >> >> On Friday, 8 March 2013 09:12:55 UTC, Gavin Williams wrote: >>> >>> Morning all >>> >>> I''m currently trying to work out a method to auto-generate a set of >>> facts. >>> These facts need to contain information about what database clones have >>> been created using NetApp SnapManager for Oracle on a given Host... >>> >>> I need the fact to give the following information: >>> clone_ACREPC11 => >>> 10.10.160.1:/vol/SnapManager_20130307153440293_v_ACTEST11_oradata/q_ACTEST11_oradata >>> >>> ACREPC11 is an generated database SID that will change across clones, >>> and the value is an auto-generated NFS export path... >>> The export path is going to be grepped out of the fstab, which I can >>> handle :D >>> >>> However there could be multiple clones on a given host, so ideally I >>> want one fact file to generate all the required facts... >>> >>> Possible? >>> >>> Cheers >>> Gavin >>> >>-- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Hmm, it seems that the new fact has broken my Network devices?! :( Getting the following when trying to run puppet against a network device: $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v Info: starting applying configuration to act-star-nactl01 at act-star-nactl01 Info: Retrieving plugin Info: Caching catalog for act-star-nactl01 Error: Failed to apply catalog: undefined method `each'' for nil:NilClass However I''ve got a catch in the fact which should stop it trying to do ''each'' on a nil class... Adding ''--trace'' to the run gives me: $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v --trace Info: starting applying configuration to act-star-nactl01 at act-star-nactl01 Info: Retrieving plugin Info: Caching catalog for act-star-nactl01 Error: Failed to apply catalog: undefined method `each'' for nil:NilClass /var/lib/puppet/lib/facter/oracle_clones.rb:6 /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load'' /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load_file'' /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:43:in `load_all'' /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:38:in `each'' /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:38:in `load_all'' /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:35:in `each'' /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:35:in `load_all'' /usr/lib/ruby/site_ruby/1.8/facter/util/collection.rb:72:in `fact'' /usr/lib/ruby/site_ruby/1.8/facter/util/collection.rb:117:in `value'' /usr/lib/ruby/site_ruby/1.8/facter.rb:98:in `send'' /usr/lib/ruby/site_ruby/1.8/facter.rb:98:in `value'' /usr/lib/ruby/site_ruby/1.8/puppet/provider.rb:182:in `default?'' /usr/lib/ruby/1.8/fileutils.rb:243:in `find'' /usr/lib/ruby/site_ruby/1.8/puppet/provider.rb:180:in `each'' /usr/lib/ruby/site_ruby/1.8/puppet/provider.rb:180:in `find'' /usr/lib/ruby/site_ruby/1.8/puppet/provider.rb:180:in `default?'' /usr/lib/ruby/site_ruby/1.8/puppet/type.rb:1254:in `defaultprovider'' /usr/lib/ruby/1.8/fileutils.rb:243:in `find_all'' /usr/lib/ruby/site_ruby/1.8/puppet/type.rb:1254:in `each'' /usr/lib/ruby/site_ruby/1.8/puppet/type.rb:1254:in `find_all'' /usr/lib/ruby/site_ruby/1.8/puppet/type.rb:1254:in `defaultprovider'' /usr/lib/ruby/site_ruby/1.8/puppet/type.rb:1377:in `default'' /usr/lib/ruby/site_ruby/1.8/puppet/type.rb:512:in `set_default'' /usr/lib/ruby/site_ruby/1.8/puppet/type.rb:1649:in `initialize'' /usr/lib/ruby/site_ruby/1.8/puppet/resource.rb:290:in `new'' /usr/lib/ruby/site_ruby/1.8/puppet/resource.rb:290:in `to_ral'' /usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:570:in `send'' /usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:570:in `to_catalog'' /usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:551:in `each'' /usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:551:in `to_catalog'' /usr/lib/ruby/site_ruby/1.8/puppet/resource/catalog.rb:475:in `to_ral'' /usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:82:in `convert_catalog'' /usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:77:in `retrieve_catalog'' /usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:107:in `prepare_and_retrieve_catalog'' /usr/lib/ruby/site_ruby/1.8/puppet/configurer.rb:159:in `run'' /usr/lib/ruby/site_ruby/1.8/puppet/application/device.rb:198:in `main'' /usr/lib/ruby/site_ruby/1.8/puppet/application/device.rb:176:in `each_value'' /usr/lib/ruby/site_ruby/1.8/puppet/application/device.rb:176:in `main'' /usr/lib/ruby/site_ruby/1.8/puppet/application.rb:354:in `run_command'' /usr/lib/ruby/site_ruby/1.8/puppet/application.rb:346:in `run'' /usr/lib/ruby/site_ruby/1.8/puppet/application.rb:438:in `plugin_hook'' /usr/lib/ruby/site_ruby/1.8/puppet/application.rb:346:in `run'' /usr/lib/ruby/site_ruby/1.8/puppet/util.rb:496:in `exit_on_fail'' /usr/lib/ruby/site_ruby/1.8/puppet/application.rb:346:in `run'' /usr/lib/ruby/site_ruby/1.8/puppet/util/command_line.rb:87:in `execute'' /usr/bin/puppet:4 So looks like it is definitely my new oracle_clones.rb fact which is breaking things :( Fact looks like: https://gist.github.com/fatmcgav/5115394#file-oracle_clones-rb Any ideas??? Cheers Gavin On Friday, 8 March 2013 09:12:55 UTC, Gavin Williams wrote:> > Morning all > > I''m currently trying to work out a method to auto-generate a set of facts. > These facts need to contain information about what database clones have > been created using NetApp SnapManager for Oracle on a given Host... > > I need the fact to give the following information: > clone_ACREPC11 => > 10.10.160.1:/vol/SnapManager_20130307153440293_v_ACTEST11_oradata/q_ACTEST11_oradata > > ACREPC11 is an generated database SID that will change across clones, and > the value is an auto-generated NFS export path... > The export path is going to be grepped out of the fstab, which I can > handle :D > > However there could be multiple clones on a given host, so ideally I want > one fact file to generate all the required facts... > > Possible? > > Cheers > Gavin >-- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On Friday, March 8, 2013 9:43:30 AM UTC-6, Gavin Williams wrote:> > Hmm, it seems that the new fact has broken my Network devices?! :( > > Getting the following when trying to run puppet against a network device: > $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v > Info: starting applying configuration to act-star-nactl01 at > act-star-nactl01 > Info: Retrieving plugin > Info: Caching catalog for act-star-nactl01 > Error: Failed to apply catalog: undefined method `each'' for nil:NilClass > > However I''ve got a catch in the fact which should stop it trying to do > ''each'' on a nil class... > Adding ''--trace'' to the run gives me: > $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v > --trace > Info: starting applying configuration to act-star-nactl01 at > act-star-nactl01 > Info: Retrieving plugin > Info: Caching catalog for act-star-nactl01 > Error: Failed to apply catalog: undefined method `each'' for nil:NilClass > /var/lib/puppet/lib/facter/oracle_clones.rb:6 > /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load'' >[...]> Any ideas??? > >That''s weird. The code at that URL is broken, but it shouldn''t have produced the trace you presented. Are you sure the trace and that version of the code go together? Anyway, here''s how I might write it: # Get a list of running dbs... running_dbs = Facter::Util::Resolution.exec("ps -ef |grep [o]ra_pmon |awk {''print $8''} |awk ''BEGIN{FS=\"_\";} {print $3}''") # JCB: running_dbs will not be empty, but no problem if it were # JCB: must still watch out for nil, however unless running_dbs.nil? # JCB: must use lines() or each_line(), not each() running_dbs.lines.grep(/REPC/).each do |db| # Add fact Facter.add("clone_#{db}") do setcode { # JCB: prefer to put fact evaluation code into the setcode() block # The fact value is the export path # JCB: ensure that the fact value is not nil Facter::Util::Resolution.exec("grep #{db} /etc/fstab | awk {''print $1''}") or '''' } end end end 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On Monday, March 11, 2013 9:44:54 AM UTC-5, jcbollinger wrote:> > # JCB: must use lines() or each_line(), not each() > > running_dbs.lines.grep(/REPC/).each do |db| > >I see that that comment might be confusing, since I do ultimately use each(). The comment was written toward the original code, which invoked running_dbs.each(). The running_dbs variable will contain a string, however, and strings do not have an ''each'' method. The replacement code invokes ''lines'' on the string instead, selects those lines of the result that match the given regex, and iterates over the resulting array using *its * ''each'' method. 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
John Cheers for that... Still getting the hang of Ruby, and looks like it allows code to be cut down to a one liner quite easily :D Will give your code a test and report back... Cheers Gavin On Monday, 11 March 2013 14:44:54 UTC, jcbollinger wrote:> > > > On Friday, March 8, 2013 9:43:30 AM UTC-6, Gavin Williams wrote: >> >> Hmm, it seems that the new fact has broken my Network devices?! :( >> >> Getting the following when trying to run puppet against a network device: >> $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v >> Info: starting applying configuration to act-star-nactl01 at >> act-star-nactl01 >> Info: Retrieving plugin >> Info: Caching catalog for act-star-nactl01 >> Error: Failed to apply catalog: undefined method `each'' for nil:NilClass >> >> However I''ve got a catch in the fact which should stop it trying to do >> ''each'' on a nil class... >> Adding ''--trace'' to the run gives me: >> $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v >> --trace >> Info: starting applying configuration to act-star-nactl01 at >> act-star-nactl01 >> Info: Retrieving plugin >> Info: Caching catalog for act-star-nactl01 >> Error: Failed to apply catalog: undefined method `each'' for nil:NilClass >> /var/lib/puppet/lib/facter/oracle_clones.rb:6 >> /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load'' >> > > > [...] > > > >> Any ideas??? >> >> > > That''s weird. The code at that URL is broken, but it shouldn''t have > produced the trace you presented. Are you sure the trace and that version > of the code go together? Anyway, here''s how I might write it: > > # Get a list of running dbs... > running_dbs = Facter::Util::Resolution.exec("ps -ef |grep [o]ra_pmon |awk {''print $8''} |awk ''BEGIN{FS=\"_\";} {print $3}''") > > # JCB: running_dbs will not be empty, but no problem if it were > # JCB: must still watch out for nil, however > unless running_dbs.nil? > # JCB: must use lines() or each_line(), not each() > running_dbs.lines.grep(/REPC/).each do |db| > # Add fact > Facter.add("clone_#{db}") do > setcode { > # JCB: prefer to put fact evaluation code into the setcode() block > # The fact value is the export path > # JCB: ensure that the fact value is not nil > Facter::Util::Resolution.exec("grep #{db} /etc/fstab | awk {''print $1''}") or '''' > } > end > end > end > > > > 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
John I''ve updated to use the new fact, however I''m getting some intermittent hanging issues when Puppet agent is loading facts... Tracked it down to the below fact, and specifically it looks like a ''\n'' is creeping into the db var, which is causing the grep exec to hang :( Put in some additional logging, and got this output: Starting fact test script... Running_dbs "SWREPC01\nSWPROD01" Running dbs isnt nil... Lines ["SWREPC01\n"] Got a REPC database... "SWREPC01\n" Command = /bin/grep SWREPC01 /etc/fstab What I''m struggling with is how to remove the \n character easily as part of the existing code... :s Any ideas??? Cheers Gavin On Monday, 11 March 2013 14:44:54 UTC, jcbollinger wrote:> > > > On Friday, March 8, 2013 9:43:30 AM UTC-6, Gavin Williams wrote: >> >> Hmm, it seems that the new fact has broken my Network devices?! :( >> >> Getting the following when trying to run puppet against a network device: >> $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v >> Info: starting applying configuration to act-star-nactl01 at >> act-star-nactl01 >> Info: Retrieving plugin >> Info: Caching catalog for act-star-nactl01 >> Error: Failed to apply catalog: undefined method `each'' for nil:NilClass >> >> However I''ve got a catch in the fact which should stop it trying to do >> ''each'' on a nil class... >> Adding ''--trace'' to the run gives me: >> $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v >> --trace >> Info: starting applying configuration to act-star-nactl01 at >> act-star-nactl01 >> Info: Retrieving plugin >> Info: Caching catalog for act-star-nactl01 >> Error: Failed to apply catalog: undefined method `each'' for nil:NilClass >> /var/lib/puppet/lib/facter/oracle_clones.rb:6 >> /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load'' >> > > > [...] > > > >> Any ideas??? >> >> > > That''s weird. The code at that URL is broken, but it shouldn''t have > produced the trace you presented. Are you sure the trace and that version > of the code go together? Anyway, here''s how I might write it: > > # Get a list of running dbs... > running_dbs = Facter::Util::Resolution.exec("ps -ef |grep [o]ra_pmon |awk {''print $8''} |awk ''BEGIN{FS=\"_\";} {print $3}''") > > # JCB: running_dbs will not be empty, but no problem if it were > # JCB: must still watch out for nil, however > unless running_dbs.nil? > # JCB: must use lines() or each_line(), not each() > running_dbs.lines.grep(/REPC/).each do |db| > # Add fact > Facter.add("clone_#{db}") do > setcode { > # JCB: prefer to put fact evaluation code into the setcode() block > # The fact value is the export path > # JCB: ensure that the fact value is not nil > Facter::Util::Resolution.exec("grep #{db} /etc/fstab | awk {''print $1''}") or '''' > } > end > end > end > > > > 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Think I''ve sorted it actually... Did this: ==================================================================--- lib/facter/oracle_clones.rb (revision 96307) +++ lib/facter/oracle_clones.rb (working copy) @@ -9,7 +9,7 @@ Facter.add("clone_#{db}") do setcode { # Look for a mount point, or set to nothing. - Facter::Util::Resolution.exec("grep #{db} /etc/fstab | awk {''print $1''}") or '''' + Facter::Util::Resolution.exec("grep #{db.chomp} /etc/fstab | awk {''print $1''}") or '''' } end end Now to see how reliable it is :D Cheers Gav On Wednesday, 13 March 2013 12:53:37 UTC, Gavin Williams wrote:> > John > > I''ve updated to use the new fact, however I''m getting some intermittent > hanging issues when Puppet agent is loading facts... > > Tracked it down to the below fact, and specifically it looks like a ''\n'' > is creeping into the db var, which is causing the grep exec to hang :( > > Put in some additional logging, and got this output: > > Starting fact test script... > Running_dbs > "SWREPC01\nSWPROD01" > Running dbs isnt nil... > Lines > ["SWREPC01\n"] > Got a REPC database... "SWREPC01\n" > Command = /bin/grep SWREPC01 > /etc/fstab > > What I''m struggling with is how to remove the \n character easily as part > of the existing code... :s > > Any ideas??? > > Cheers > Gavin > > On Monday, 11 March 2013 14:44:54 UTC, jcbollinger wrote: >> >> >> >> On Friday, March 8, 2013 9:43:30 AM UTC-6, Gavin Williams wrote: >>> >>> Hmm, it seems that the new fact has broken my Network devices?! :( >>> >>> Getting the following when trying to run puppet against a network device: >>> $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v >>> Info: starting applying configuration to act-star-nactl01 at >>> act-star-nactl01 >>> Info: Retrieving plugin >>> Info: Caching catalog for act-star-nactl01 >>> Error: Failed to apply catalog: undefined method `each'' for nil:NilClass >>> >>> However I''ve got a catch in the fact which should stop it trying to do >>> ''each'' on a nil class... >>> Adding ''--trace'' to the run gives me: >>> $ sudo puppet device --deviceconfig devices/act-star-nactl01.conf -v >>> --trace >>> Info: starting applying configuration to act-star-nactl01 at >>> act-star-nactl01 >>> Info: Retrieving plugin >>> Info: Caching catalog for act-star-nactl01 >>> Error: Failed to apply catalog: undefined method `each'' for nil:NilClass >>> /var/lib/puppet/lib/facter/oracle_clones.rb:6 >>> /usr/lib/ruby/site_ruby/1.8/facter/util/loader.rb:81:in `load'' >>> >> >> >> [...] >> >> >> >>> Any ideas??? >>> >>> >> >> That''s weird. The code at that URL is broken, but it shouldn''t have >> produced the trace you presented. Are you sure the trace and that version >> of the code go together? Anyway, here''s how I might write it: >> >> # Get a list of running dbs... >> running_dbs = Facter::Util::Resolution.exec("ps -ef |grep [o]ra_pmon |awk {''print $8''} |awk ''BEGIN{FS=\"_\";} {print $3}''") >> >> # JCB: running_dbs will not be empty, but no problem if it were >> # JCB: must still watch out for nil, however >> unless running_dbs.nil? >> # JCB: must use lines() or each_line(), not each() >> running_dbs.lines.grep(/REPC/).each do |db| >> # Add fact >> Facter.add("clone_#{db}") do >> setcode { >> # JCB: prefer to put fact evaluation code into the setcode() block >> # The fact value is the export path >> # JCB: ensure that the fact value is not nil >> Facter::Util::Resolution.exec("grep #{db} /etc/fstab | awk {''print $1''}") or '''' >> } >> end >> end >> end >> >> >> >> 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Toni Schmidbauer
2013-Mar-13 13:06 UTC
Re: [Puppet Users] Re: Auto-generate multiple facts
At Wed, 13 Mar 2013 05:53:37 -0700 (PDT), Gavin Williams wrote:> What I''m struggling with is how to remove the \n character easily as part > of the existing code... :sdb.chomp! regards toni -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.