On Fri, Mar 23, 2012 at 3:42 AM, Pablo Fernandez <pablo.fernan...@cscs.ch>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?
>

I would ask how you could classify a node's primary or secondary group
based on looking at?  Is there a file on disk that indicates its group?
 Will you use its IP address?  Hostname?  Something like this?

It sounds like you want to use Puppet to place a file on the filesystem
indicating its primary_group, but that you want to Puppet to manage this
file (or you want to manage the data in Puppet itself).  You have a number
of options here:

1.  Use something atomic about the machine to determine its primary_group.
 If you can say 'based on its IP address, it should be in this group' or
'based on its hostname, it will be in THIS group', then write a fact to
determine this for you.  Remember that in your custom fact you can do:
 Facter.value(:ipaddress) or Facter.value(:hostname) to get a node's
ipaddress or hostname.  This is the better method since it relies on
something NOT provided by Puppet to determine its group.  The Facter fact
would run before the Puppet run, determine its group, and then you'd be
fine.  Most places I visit do something like this.

2.  Do something at provision-time.  Do you already have a source of truth
that maps each node to a primary_group?  In your kickstart before running
Puppet you could query this source of truth and create a file (to be read
by a fact) that would determine the primary_group.

3.  Set it in the %{fqdn} level of the Hiera hierarchy.  This is
less-optimal as you would need to create a YAML file for every node in your
infrastructure and set its 'primary_group' parameter in the YAML file.  If
you don't have a source of truth that maps each node to a primary_group,
and you can't determine the group based on something ABOUT the node itself
(as in case #1), then Hiera can/will be your node/group source of truth.

Does this sound like what you need?



>
>
> 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?
>
>
>
> 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 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.
>



-- 

Gary Larizza
Professional Services Engineer
Puppet Labs

-- 
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.

Reply via email to