Ahhh your right, that's not going to work. Ok...
I know that some people use %{calling_class} and %{calling_module} in
their hiera.yaml (I don't) so that means the hiera Puppet function must
get some of the Puppet catalog's state that's not just Facts. In this file:
https://github.com/puppetlabs/hiera-puppet/blob/master/lib/hiera/scope.rb
You can see those variables are treated differently, when the key is
"calling_class" the answer is looked up differently. If you could figure
out the correct notation to lookup from Puppet class scope you could
hack in your groups here.
if key == "primary_group"
ans = @real.scope.lookup_var(...)
I don't know enough Ruby to help you, but someone on the list should. Of
course you have to run a patched version of hiera-puppet. You may just
want to do the 2 pass chicken and egg solution now ;-)
On 24/03/12 09:58, Fernandez Pablo wrote:
Hi,
That would define $primary_group as a variable, not as a fact. Indeed, what I
want to do is:
:backends: - puppet
:hierarchy: - %{primary_group}
:puppet:
:datasource: data
And that requires primary_group to be a fact.
Any other ideas?
Thanks!
Pablo
________________________________________
From: [email protected] [[email protected]] on behalf
of Luke Bigum [[email protected]]
Sent: Friday, March 23, 2012 2:52 PM
To: [email protected]
Subject: Re: [Puppet Users] Plugins and Hiera
Ok, I would say to try hiera-puppet then. I was going to quote you a list post
but you're actually the OP so maybe you've already tried and it hasn't worked
so well. I don't use it myself so this is all theoretical, but could you not do
something like this:
class module::data {
if (tagged(green::group)) {
$primary_group = 'green'
} else {
$primary_group = 'red'
}
}
Then have that data class in your hiera.yaml:
---
:backends: - puppet
:puppet:
:datasource: data
-Luke
On 23/03/12 12:16, Pablo Fernandez wrote:
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]<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]<mailto:[email protected]>.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
--
Luke Bigum
Information Systems
Ph: +44 (0) 20 3192 2520
[email protected]<mailto:[email protected]> | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN
The information in this e-mail and any attachment is confidential and is
intended only for the named recipient(s). The e-mail may not be disclosed or
used by any person other than the addressee, nor may it be copied in any way.
If you are not a named recipient please notify the sender immediately and
delete any copies of this message. Any unauthorized copying, disclosure or
distribution of the material in this e-mail is strictly forbidden. Any view or
opinions presented are solely those of the author and do not necessarily
represent those of the company.
--
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.
--
Luke Bigum
Information Systems
Ph: +44 (0) 20 3192 2520
[email protected] | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN
The information in this e-mail and any attachment is confidential and is
intended only for the named recipient(s). The e-mail may not be disclosed or
used by any person other than the addressee, nor may it be copied in any way.
If you are not a named recipient please notify the sender immediately and
delete any copies of this message. Any unauthorized copying, disclosure or
distribution of the material in this e-mail is strictly forbidden. Any view or
opinions presented are solely those of the author and do not necessarily
represent those of the company.
--
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.