Hello.

Here is a custom fact I created for enumerating netgroups from an ldap
directory. As I'm a total ruby newbie, I'd be interested by review for it.
-- 
BOFH excuse #439:

Hot Java has gone cold

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
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.

#!/usr/bin/ruby -w

require 'ldap'
require 'socket'

$HOST = 'ldap.saclay.inria.fr'
$PORT = LDAP::LDAP_PORT
base = 'ou=netgroups,dc=saclay,dc=inria,dc=fr'
scope = LDAP::LDAP_SCOPE_SUBTREE
filter = '(objectclass=nisNetgroup)'
attrs = ['cn', 'nisNetgroupTriple']

hostname = Socket::gethostname
regex = /#{hostname}/

Facter.add("netgroups") do
    setcode do
        netgroups = Array.new()
        conn = LDAP::Conn.new($HOST, $PORT)
        begin
            conn.search(base, scope, filter, attrs) { |entry|
                cn = entry.vals('cn')
                entry.vals('nisNetgroupTriple').each { |val|
                    if (regex.match(val))
                        netgroups << cn
                    end
                }
            }
        rescue LDAP::ResultError
            exit
        end
        conn.unbind
        netgroups.join(",")
    end
end

Reply via email to