Guillem,
Sorry for the delayed response. Anyway, John is correct about what you're
trying to do with Hiera. I can say as far as the ENC Gary has written follows
all the rules of what an ENC 'should do' as per the documentation.
http://docs.puppetlabs.com/guides/external_nodes.html
Keep in mind also, when the ENC is run, the only information it has access to
is the Facts from the node. The manifests are not compiled until after the ENC
returns the classes it has determined should be declared. This ENC does it in
one call to hiera for classes. When this Hiera ENC processes, it never adds the
discovered parameters and other variables to the current running context. While
that could achieve what you want, it could also complicate things in unexpected
ways. So as I said above, when the ENC runs, you only have just the facts from
the host as your current context.
John's suggestion of a new usage model that aligns better with Hiera's design
is probably the best answer. That being a case, I would suggest custom facts to
help you navigate your hiera tree in a more controlled/granular manner.
--
Tom Linkin
Professional Services Engineer
http://puppetlabs.com/
twitter: @trlinkin
On Monday, October 1, 2012 at 10:47 AM, jcbollinger wrote:
On Wednesday, September 26, 2012 10:52:19 AM UTC-5, Guillem Liarte wrote:
This is the situation I have:
All my hosts are the same OS.
All my host are in the same puppet environment, so I cannot use
%{environment}
I have a module that sets all the basic functionality for the OS,
resolution, authentication, security, packages, etc
I have a module for each application hosted.
At the moment all the 'data' is in Puppet, mostly in parametrised classes
in site.pp.
What I want to get is a hiera set-up that allows me to use this structure:
I suspect that one of the reasons you are having trouble is that you are
trying to employ a usage paradigm that is inconsistent with hiera's design
(more below).
:hierarchy:
- global # source of application names (classes? modules?) and
environments list
- basic # data for the basic class
There's nothing wrong with those levels.
- prod/%{application}/%{hostname}# hostname files for specific
data
- prod/%{application}/%{env} # environmental data for
each application (module)
- prod/%{application}/default # default data for an
application
But there is a problem with those. It may be possible to make it work, but
it's shaky to use variable hierarchy levels for data selection. That's what
keys are for. With that said, recent Puppet releases provide automatic
$calling_module and $calling_class variables, one of which you could probably
use in place of $application. As I understand it, that's intended to provide
(better) support for module-specific data, which might be a good way to cast
that part of your problem.
- nonprod/%{sysclass}/%{hostname}
- nonprod/%{sysclass}/%{env}
- nonprod/%{sysclass}/default
You additionally have a fundamental problem with %{env}. Hiera will attempt
to resolve that as a Puppet variable, to which the presence of a matching key
somewhere in the Hiera hierarchy is irrelevant. Hiera needs to know the
value to resolve the hierarchy (as you have defined it), and it would need,
in principle, to resolve the hierarchy before it could look up the value in
your data store.
What actually happens, I'm sure, is that hiera uses the value of $::env that
it looks up in Puppet at function entry. You might be able to work around
that by setting that variable in Puppet before looking up other data, such as
by putting
$env = hiera('env')
at top scope near the beginning of your site.pp.
So in short, I would like hiera to be a source of facts, where I can get
information that feeds Puppet in order to classify the nodes and to feed
the parametrised classes.
As an aside, throwing parametrized classes into this mix has only downside as
far as I am concerned, except inasmuch as you may want to use parametrized
classes that are (unwisely) provided by modules written by others. Since you
want to rely on hiera (which is good), it is superior to write your classes
like this wherever you are in control of module interfaces:
class mymodule::class1 {
$param1 = hiera('mymodule::class1::param1')
$param2 = hiera('mymodule::class1::param2')
# or with simpler keys enabled by use of
# %{calling_module} and/or %{calling_class}
}
There are several advantages, among them that you can encode interclass
parse-order dependencies via the built-in 'include' function, and that you
can use hiera's 'hiera_include()' function to assign such classes to nodes.
I recently found this blog entry:
http://garyhetzel.com/2012/04/12/hiera_as_a_puppet_enc
Gary appears to have done some cool