On Wednesday, August 22, 2012 1:56:49 PM UTC-5, Nigel Kersten wrote:
>
> On Wed, Aug 22, 2012 at 11:13 AM, ZJE <count...@gmail.com <javascript:>> 
> wrote: 
> > The slowdown comes from the command that I run before any Facter.add 
> > statements. It takes roughly 1.5 seconds to run and I would need to run 
> it 
> > roughly 64 times if I had it in each Facter.add. Many facts are 
> generated by 
> > a loop that contains a Facter.add, so I feel like some sort of exception 
> > would make things easier.  I'd like to avoid using a "giant if 
> statement" if 
> > possible (there are roughly 100 lines of code that would be 
> encapsulated). 
> > One of the main issues I have is that there are two different checks 
> that 
> > happen in different parts of the code. I recognize that some may 
> consider 
> > adding more if-statements as increased readability, but I feel like the 
> > added indentation for large chunks of code causes confusion for readers 
> > (especially when looking at loops). 
> > 
> > Thanks so much for your reply! 
>
> You should be able to do something like this, which worked for the 
> quick test I did, but I haven't extensively tested it. 
>
> arr = ["one", "two", "three", "four"] 
>
> if true then 
>   # exit due to conditions for not running on this host 
>   exit 
> else 
>   # run the command you'd run and store in an instance variable 
> end 
>
> arr.each do |e| 
>   Facter.add("tester_#{e}") do 
>     setcode do 
>       "bleah" 
>     end 
>   end 
> end 
>


Hi Nigel,

Thanks again for your reply. Currently, I'm using "exit" - but I think this 
causes the entire facter run to stop prematurely. If my script ends up 
being the first custom fact run, facter actually outputs nothing. Could 
there be a different problem? 

For example, if FACTERLIB=/opt/facter/facts and my custom fact looks like 
this:
---
cat /opt/facter/facts/bailfact.rb 
#!/usr/bin/ruby
Facter.debug "In bailfact!"
exit
---

I get:
---
[root@testhost ~]# facter -d
Relative directory ./facter removed from search path.
Not an EC2 host
in bail fact!
---

and nothing else.

If it helps, I'm using facter 2.0.0rc4

Thanks!

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

Reply via email to