On Thursday, February 20, 2014 9:21:02 AM UTC-6, Daniel K. wrote:
>
> Hello everyone,
>
> i am trying to write my first custom fact but i don't know how. I didn't 
> find any good instructions or list of functions i can use.
>


Well, the first place to look for docs would be among PL's online facter 
docs: http://docs.puppetlabs.com/guides/custom_facts.html.
 

>
> What i want to do is the following:
>
> On our machines we have the directory "/work", There is a list of all 
> possible subdirectories, but no machine has all of them.
> Depending on the existence of the subdirectories i have to create files. 
> Now all i need is a fact that gives me all subdirectories of "/work" but 
> only depth=1.
>
> e.g.
> /work
>    |_ Sub_a
>    |_ Sub_b
>         |_ Sub_b_c
>
> I would only need "Sub_a" and "Sub_b" returned by the fact.
>
> Does anyone know how to do it?
>
>

This shouldn't be too hard.  Supposing you do it as a Ruby plugin, the Ruby 
code might look something like this:

work_dirs.rb:
=========

Facter.add('work_dirs') do
  setcode do
    begin
      Dir.entries('/work').select {|entry| File.directory?(entry) 
}.join(',')
    rescue SystemCallError => not_a_directory
      ''      
    end
  end
end


The fact value for your example would be 'Sub_a,Sub_b', which you would 
need to split inside Puppet if you need them in array form.  (Puppet and 
Facter do not currently support arrary-valued facts.)


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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/90e38836-d5ce-45a8-98b5-1b9580f564c5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to