Hi,
Thanks for the code. My problem is a bit more complex than that... I want to
define something within puppet, that gets converted into a fact, and is loaded
before puppet. It's a bit chicken-egg problem:
- I need the fact to be able to select within the hiera hierarchy.
- I want to set up the fact inside puppet
- But puppet runs after the facts have been loaded, and I want to have all in
one single puppet run.
So, the Ruby plugin should be able to pick up information from the puppet tree
to provide the right facts.
I could create different plugins, one for each "group", and do an include of
those that I actually want to include... but how do I do that? How do you
select which plugins to load, from inside the puppet code?
Thanks!
Pablo
On Friday 23 March 2012 11:04:38 Luke Bigum wrote:
> Hi Pablo,
>
> The Ruby part of Facts is a little daunting at first but not too
> difficult, here's an example with some added comments:
>
> #This custom fact simple tests if a file exists and sets the fact true
> #or false.
> #simple conditional logic to decide whether this Fact gets set or not
> if File.exists?("/var/lib/puppet/rebirth_managed_network") and
> File.exists?("/usr/bin/virt-install")
> #Start of the Fact method, defines the name of the Fact
> Facter.add("rebirth_libvirt_ready") do
> #The confine line will ensure this Fact only appears for Linux
> kernels, would thus exclude Solaris and Windows machines
> confine :kernel => :linux
> #start the block of code that will generate the value of the Fact
> setcode do
> #Since this is a simple boolean Fact, can just call 'true'
> true
> end
> end
> end
>
> This blog post is helpful:
>
> http://ppadron.blog.br/2009/09/25/facter-puppet-writing-custom-facts-to-mana
> ge-plesk-servers/
>
> When developing facts remember that you can set FACTERLIB to the
> directory that contains the Fact you're writing and run 'facter -p' to
> test it.
>
> On 23/03/12 10:42, Pablo Fernandez wrote:
> > Dear all,
> >
> > This is a continuation of another thread, but I think the question
> > diverged enough to create a new one.
> >
> > I have a hiera hierarchy like this:
> > :hierarchy:
> > - %{fqdn}
> >
> > - %{secundary_group}
> >
> > - %{primary_group}
> >
> > - %{productname}
> >
> > - all
> >
> > And I need to define the secondary/primary groups as facts, on the
> > nodes. Gary has suggested me to use plugins, that they will provide
> > the facts before puppet runs... but I was thinking: for plugins to
> > give facts, taken directly from within the puppet code, puppet needs
> > to run first, doesn't it?
> >
> > So, I guess I could create a module and a ruby script:
> >
> > - mygroups/lib/facter/addgroup.rb
> >
> > And write some code in Ruby to call Facter.add(:primary_group).
> >
> > My problem is (besides the fact that I know nothing about Ruby)... how
> > do I insert the values for primary_group and secondary_group inside
> > that function, within a simple puppet run?
>
> Technically you're not inserting them inside a Puppet run, it's done as
> part of Facter, which runs before Puppet gets to do any real work.
>
> I'm not exactly sure where you get your primary and secondary groups
> from, are they user defined or is there something on your servers that
> describes what a server's group is? If there is, then a Fact is the best
> way to get this information into Puppet. This could be a config file
> (like /etc/facts.d/groups below), maybe something in your server's
> hostname or the packages installed on the server?
>
> If however they are completely arbitrary groups that are defined inside
> Puppet itself then the hiera-puppet module might help, as this allows
> you to pull variables out of specifics class. There's been some recent
> posts on the list about how to use hiera-puppet.
>
> > I guess I could use a file with the definitions, like
> > /etc/facts.d/groups... but that would require two puppet runs: one to
> > create the file, and the second that loads the facts.
> >
> > I was thinking of a possible alternative... a module "mygroups" with
> > sub-classes, that I import from the nodes:
> >
> > node 'blabla' { include mygroups::green }
> >
> > And then in the module, make a mygroups/lib/facter/green.rb that does
> > Facter.add(:primary_group) = 'green' (or however you do it with Ruby).
> > But how do I make sure the module green.rb is loaded, but not the
> > other modules that will be there too?
>
> Note that *all* Custom Facts are synced to every agent regardless of
> what module they appear in, so this approach will not work.
>
> > Or maybe I could use parameters, that the plugin will recognize somehow?
> >
> > I hope the questions are clear enough, because this is clearly not
> > clean in my head.
> >
> > Thanks!
> > Pablo
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.