--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 07/11/2012 10:03 PM, Jo Rhett wrote:So I tried to get smarter, and put logic to add the group to each memberunder the appropriate classClass users::dev inherits users {User['jrhett'] { groups +> ['dev'] }}
This works… almost. It works for all instances where the user is only
subclassed once. But if I do the same technique in multiple classes I get
sound approach, but I've hit this wall a couple of times as well.
I've resorted to horrors that would add items to array variables that
are declared in a central, well-known class, and use the final value for
the resources in question. Depending on how much flexibility is
required, this may not be feasible at all.
Perhaps hiera can be used to do something clever here?
If it is the case that each user always has the same potential secondary groups, and you need to narrow the actual secondary groups to those that are actually present, then I think you could do it without too much pain. The main ingredients would be a list (array) of the groups that are supposed to be present, and a custom function that forms the intersection of two arrays. (Or you could use an inline template and split(), but yuck!)
Hiera would probably provide a good means for building the list of available groups, which you could then use not only to filter user definitions but also to drive virtual group realization. Here's a skeleton of how it might work:
class auth::constants {
$available_groups = hiera('groups')
}
# Virtual user declarations, such as
@user { 'jbolling':
uid => 4200,
gid => 4200,
groups => intersect(['dev', 'support', 'ops'], $auth::constants::available_groups)
}
}
On Jul 12, 2012, at 6:46 AM, jcbollinger wrote:If it is the case that each user always has the same potential secondary groups, and you need to narrow the actual secondary groups to those that are actually present, then I think you could do it without too much pain. The main ingredients would be a list (array) of the groups that are supposed to be present, and a custom function that forms the intersection of two arrays. (Or you could use an inline template and split(), but yuck!)
Hiera would probably provide a good means for building the list of available groups, which you could then use not only to filter user definitions but also to drive virtual group realization. Here's a skeleton of how it might work:
class auth::constants {
$available_groups = hiera('groups')
}Interesting idea, but depends on an external datasource that tells us which groups are valid. Since all of these groups are already defined in puppet, I simply don't see the value of managing intersections of data between a hiera data source and puppet.
# Virtual user declarations, such as
@user { 'jbolling':
uid => 4200,
gid => 4200,
groups => intersect(['dev', 'support', 'ops'], $auth::constants::available_groups)
}
}I think the intersect idea is valid, as long as I can find out if a parameter is realized or not. Basically, write a function that removes from the array any group which isn't realized. This removes any need for heira. However I'm poking around and the docs don't show any methods to determine if something has been realized or not.If I am reading this right, intersect is provided by stdlib, right?
So I really just need to write a function to determine if something is realized or not. I suspect this is going to fall back to the same issues as defined() unless I can delay execution until the end.
I would avoid that variation on this approach if at all possible. You would sidestep multiple pitfalls if you could determine up front, based on node name and facts, which groups are supposed to be present, instead of attempting to determine after the fact which were realized. Indeed, you might even find it convenient to use that information to drive group realization.
If nothing else, doing so would ensure that users aren't assigned to secondary groups that don't get realized.
On 07/13/2012 05:02 PM, jcbollinger wrote:
> More generally, people recommending various possible data sources to you
> -- hiera, ENC, etc. -- are not implying that you should "spread out"
> your data. That's a function of your own manifest designs and how you
> use the data. You do a disservice to those volunteering their help to
> you by criticizing them for deficiencies in /your imagined applications/
> of their suggestions.
Though he did put it quite bluntly, I do believe that Jo has a point.
The thing is, I generally want my manifests to be clever about some
things. When I include my mysql development class, I may want to realize
a couple of users and groups as a result (hypothetically speaking - I
have no such class nor such requirements, but there are other things in
this vein).
I would tell hiera to have puppet include the mysql development class,
not each single user and group. That would strike me as silly.
Relying on a single source of information is exactly what what I have suggested you do, specifically by using an up-front group list both to filter users' declared secondary groups and to drive which groups get realized. I have described that three times now, and it's included in the example code I posted earlier. You can populate such a list by whatever means you want and from whatever source you want, and you can store it wherever you want, so long as you produce the entire list before any part of it is needed.
So no, I'm not suggesting you mirror information from your puppet manifests. Rather, I am suggesting that you move implicit information out of your manifests to someplace more accessible. Study my example if you still don't understand what I mean by that. The "someplace" where the information lands could be an explicit expression elsewhere in your manifests, or it could be external, as seems best to you. The information implicitly encoded in the structure of your manifests and/or developed during compilation is inherently difficult to use from within the manifests themselves, and if you insist on using it anyway then you're choosing to be stuck in an uncomfortable position.
More generally, people recommending various possible data sources to you -- hiera, ENC, etc. -- are not implying that you should "spread out" your data. That's a function of your own manifest designs and how you use the data. You do a disservice to those volunteering their help to you by criticizing them for deficiencies in your imagined applications of their suggestions.
John,
On 07/13/2012 06:38 PM, jcbollinger wrote:
>
> I would tell hiera to have puppet include the mysql development class,
> not each single user and group. That would strike me as silly.
>
>
> Sure, but I'm not seeing how that relates. A more parallel situation
> would be if in addition, some unrelated class wanted to be able to
> determine which users and groups the mysql development class had
> declared. As Puppet now stands, the best way would be for the mysql
> development class to provide that data in class variables, or else to
> have obtained it from some shared source in the first place. The point
> is that neither of those options requires that data to be duplicated in
> the structure of the class.
I'm not sure I concur with your conclusion, nor with what you boil the
problem at hand down to.
Puppet *does* have means to implement business logic that adds resources
as implications of roles or aspects, and that is by the singleton nature
of classes. You can add users via implication of different possible
aspects of nodes by having the "aspect" class include the approprate
user class(es) for example.
Puppet even allows to make adjustments to such implied resources by
means of subclasses. If a node has a very certain role, the respective
class will include a subclass of some other feature to specialize its
resources appropriately.
All this is according to what puppet has so far been designed to do.
The problem at hand can be handled to a degree with these language
features, as the OP has successfully done already. The approach has
scaling issues, so a workaround is currently needed. I don't see why the
approach should be discarded as "not currently implemented" out of hand,
seeing as the better part of it *is* in fact possible.
I cannot, of course, but I do sympathize with Jo's notion that in order
to solve the apparently small problem of making resource overrides
scale, he is now required to rework most if not all of his manifests to
play with a hiera based approach.
Possibly something like the following pseudocode example? The main point being to only include a puppet class if there's a certain piece of data in hiera.
node default {
if hiera('usemysql') {
include mysql::service
}
if hiera_array('users') {
include users
}
}
(I haven't tested the above myself. We're still not using hiera at work, more's the pity.)
On 07/16/2012 10:29 PM, Jo Rhett wrote:We aren't, because we have no external datasource for this stuff andevery example we've seen (like yours above) indicates that we're goingto have to put half of the logic engine of puppet inside the datasource, which means it needs to be a very complex thing that enforcesthe structure and somehow ties it with the puppet logic. Our analysis sofar is that to implement hiera we're going to have to write our ownsoftware platform which manages hiera data and writes out puppetpolicies on the fly when the data changes.
Not quite. I believe that the canonical approach is to move your node ->
roles relation into hiera. This way you need little "individual"
manifest code per node.
You certainly need a means to manage hiera's datastores, but I don't
think generating manifests is required.
Apparently so. I don't want to drag this thread off into a rehash of the constraints idea, but one of the central ideas is that it allows cooperative specification of resource properties. Constraints -- as I envision them -- are not a dynamic validation feature, but rather an indirect, deferred declaration feature. In many cases, explicit resource declarations could be replaced by one or more constraints on the same resource, which could appear anywhere in the manifest set. Everything gets resolved after all resources are compiled.
I'll say no more about that here, but if anyone wants to discuss it further then I'd be likely to respond to a new thread on that topic.
On Jul 17, 2012, at 6:30 AM, jcbollinger wrote:Apparently so. I don't want to drag this thread off into a rehash of the constraints idea, but one of the central ideas is that it allows cooperative specification of resource properties. Constraints -- as I envision them -- are not a dynamic validation feature, but rather an indirect, deferred declaration feature. In many cases, explicit resource declarations could be replaced by one or more constraints on the same resource, which could appear anywhere in the manifest set. Everything gets resolved after all resources are compiled.Sounds like treating hiera data as virtualized to me (and sounds like a functional way to deal with the issues we are discussing). How would you implement this today?
I apologize for how abstract and vague that description is, but there is a great deal more design effort needed than I am prepared to exert at the moment.
Is this not the epitome of diverse and redundant dependancies? I can'tedit my hiera data without evaluating puppet manifests, I can't edit the
puppet manifests without editing the hiera data…
Rather, if you're not intending to scribble YAML files by hand (which is
entirely possible), you would have to write a web frontend or similar.