This is somewhat related to an older thread. The topic was how to install some perquisite packages for puppet, like augeas, lsb-release, cron to name just a few. Puppet is required to reinstall this packages if they are accidentally uninstalled. Because of the nature of this packages some puppet code should not run in this state.

/For example/ if lsb-release isn't installed, and clients are both ubuntu and debian, the apt package shouldn't setup sources as it might end up switching the distro. (if lsb-release isn't installed facter can not distinguish debian from ubuntu) Augeas resources if are included in the run end up failing the run, thus not allowing augeas to be installed.

My conclusion from the list was that facts should be used, so I started thinking on something extensible.

The scope is to create a set of facts and a centralizing fact. The centralizing fact is called, in my case, systemissane. Now how can I centralize these facts?

What I have tried (attached files) is to create a separte collection class, which is the bridge between facts. But the require in sane_debian_lsb is kind of hackish, not to mention that it limits these facts to a single module. So are there any better ideeas? Opinions? Is this code absolutely awful? Should I try using a common naming between the facts instead of this collection class?



Silviu

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To post to this group, send email to puppet-us...@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.

# sane.rb
# sumarization fact, indicates if the system configuration is sane
#



Facter.add("systemissane") do
    setcode do
        val = true
        Facter::Util::SaneFacts.collection.each do |factName|
            val = val && Facter[factName].value
        end
        val
    end
end
# sane_debian_lsb.rb
#
# indicates if operatingsystem may be wrong (in case of debian based systems)
#

dir = File.dirname(__FILE__)
require "#{dir}/sane_facts.rb"

Facter.add("systemislsbsane") do
    confine :operatingsystem => %w(Debian Ubuntu)

    setcode do
        count = %x[dpkg -l | grep -c lsb-release]
        count.to_i > 0
    end
end

Facter.add("systemislsbsane") do
    setcode do
        true
    end
end

Facter::Util::SaneFacts.add("systemislsbsane")
# sane_facts.rb
#
# Class that gathers all the "sane" facts.
# Or in plain English all the facts the indicate the sanity of the environment

module Facter::Util::SaneFacts

    @@collection=[]

    def self.collection
        @@collection
    end

    def self.add(sanityFactName)
        @@collection=(@@collection << sanityFactName).uniq
    end

end

Reply via email to