Hi,
I'm trying to implement a new feature of sorts and looking for some
direction from folks who understand the puppet code. What I'm trying to do
is create an ability to specify derived types via hiera much like
hiera_include() works for classes. A quick aside, and the reason I'm
interested in this to begin with, is most people I've asked suggest
wrapping all node declarations in classes, however then you end up writing
a bunch of classes that aren't really 'modules' in the practical sense of
the term, they're really node definitions packaged as modules for the sake
of declaration via hiera.
The idea here is in hiera, you can declare derived types for a node as such
# This will declare 2 file types for the node
hiera_file:
/var/yum:
ensure: directory
owner: jenkins
recurse: true
/var/yum/custom-repo:
ensure : directory
owner : jenkins
group : jenkins
require : "File['/var/yum']"
So thinking it would be cool to simply enumerate derived types in hiera I
set off to write a module to implement the feature. I started with a class
which basically looks like this
class type_mapper()
{
$augeas = hiera_hash('hiera_augeas')
if(!empty($augeas)) {
create_resources(augeas, $augeas)
}
# similar block for each built-in derived type
}
But immediately realized dependency problems with type declarations that
have 'require' et al. At first I thought I could write a function in ruby
to deal with this, but then realized the complexity of the problem and I
know there's code in puppet that handles this sort of dependency resolution
already. I'm just looking around the source some and haven't found it yet.
The function I'm trying to write would look something like this
module Puppet::Parser::Functions
newfunction(:hiera_declare_types) do |args|
# Raw type definitions provided by hiera
# For now the hiera_hash() call is in RDL,
# but that should move here too
types = args[0]
* #------------------------------------------------------------*
* # XXX What is the real puppet function for*
* # some_magic_puppet_dependency_reconciliation*
* #------------------------------------------------------------*
* ordered_types = some_magic_puppet_dependency_reconciliation(types)*
Puppet::Parser::Functions.function('create_resources')
# Loop over all the type declarations
ordered_types.each do |type, hash|
# Loop over the declarations for a specific type
hash.each do |title, real_hash|
create_resources(type, hash)
end
end
end
end
Is there such a function? I imagine there has to be because ultimately the
type declarations are made one at a time, in some linear order. Generally
speaking, do you see what I'm going for? Does it look like a cool addition
for puppet? I feel like without something like this, using hiera causes you
to move node definitions over to modules which isn't very attractive.
thanks,
-nathan
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-dev/50668acf-ee63-4adf-b948-5f12305f069b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.