On Feb 8, 4:03 am, Peter Valdemar Mørch <[email protected]> wrote: > Hi, > > Being a newbie, I'm trying to wrap my head around puppet. Here are my > first stumbling blocks: > > We have an output from a database which is essentially a list of users > that we want to manage in the uid 2001-2999 range: > > * No other users may be present in that range (puppet should delete them) > * Users outside that range must not be touched
Neither below nor above? Would it be sufficient if only the UIDs _below_ 2001 were protected? > * The user names change, but their uids will remain constant To give you a good answer, I need to understand this a bit better, and I'm having trouble with that statement. On Unix-like systems the user name is the primary identifier, and UIDs are only secondary. It is even possible for two or more users to have the same UID. What, then, does it mean for a user name to change while the UID remains constant? I'm looking for the big picture here, not just the /etc/ passwd view of the world. > So say that we start with no users in the 2001-2999 range and we have > this list of users in the range > > peter (uid = 2001) > henrik (uid = 2002) > fred (uid = 2003) > barney (uid = 2004) > > Creating/adding them is trivial based onhttp://docs.puppetlabs.com/learning/. > > But now say that the new desired configuration driven by the databases is: > > martin (uid = 2002) > barney (uid = 2003) > fred (uid = 2004) > sally (uid = 2005) > > How do I achieve this: > * Get puppet to discover that peter (uid = 2001) must be deleted > * Get puppet to rename henrik->martin (trivial rename) > * Get puppet to rename fred->barney and barney->fred (complicated > rename) A third temporary username will be necessary, I guess, so that > it really becomes fred->tmp, barney->fred, tmp->barney, because > otherwise an attempt will be made to have non-unique users > temporarily. This necessary temporary user name doesn't swing well > with the declarative nature of puppet, I'm guessing. You are astute. If there needs to be a renaming cycle then there is no way to describe it in Puppet DSL. You could create a custom extension of the underlying User provider that can perform such cycles, but probably you don't need to do that. > I know exactly how to achieve these things in a shell script, but I > want to use puppet. I realize I'm going to have to have the database > output converted into either facts or manifests. I guess that > pre-processing could also identify users to be deleted, and even users > to be renamed. But the two-step rename I don't know how to even model > given the declarative nature of puppet. I would recommend converting to manifests, or at least resource declarations. You will find that far easier to work with. > Is it possible to write "myuser" so that all the above is done with just: > > myuser { 2002: > name => 'martin',} > > myuser { 2003: > name => 'barney',} > > myuser { 2004: > name => 'fred',} > > myuser { 2005: > name => 'sally', > > } > > First step for a newbie is to ask the right questions. Am I even > asking the right questions? Does this make sense to anyone? Should I > just do this in a shell/perl script instead? What is it about this > task, that makes it unsuited for puppet? For just the tasks you have already mentioned, you don't need to write a 'myuser' definition. Indeed, I don't think such a defined type would be useful for getting around the issues you have identified. Puppet's built-in resource types already have features that provide much of what you describe, however. Puppet supports purging unmanaged resources, and it has a special provision for protecting 'system' user accounts from such a purge. The principal caveat is that Puppet defines 'system' accounts as those having UIDs less than or equal to a configurable upper bound. Out of the box, it cannot limit a user purge to a range of UIDs that is bounded above. If it would be sufficient to bound the purge range only below, then you could do this: resources { "user": purge => true, unless_system_user => 2000 } Purging is the only activity Puppet supports for (otherwise) unmanaged resources. If you do need to avoid purging accounts having UIDs greater than 2999, however, then it probably wouldn't be too hard to hack that into your Puppet. Or you could submit a feature request. Or, a feature request accompanied by code and appropriate test cases if you want the best chance of getting it quickly into the official Puppet codebase. If only a small number of accounts have UIDs above 2999, then you could make the out-of-the-box purging support work for you by simply putting those accounts under management. (Indeed, you could do the same for some or all of the accounts with UIDs below 2001, too.) That would be more consistent with the Puppet paradigm anyway. Puppet probably can handle your complex renaming cases by transiently leveraging the ability (available on many, but not all, client OSs) for one UID to be assigned to multiple users: user { 'martin': uid => 2002, allowdupe => true, } user { 'barney': uid => 2003, allowdupe => true, } user { 'fred': uid => 2004, allowdupe => true, } user { 'sally': uid => 2005, allowdupe => true, } So far, none of this touches on user home directories. Puppet's User resource does have the ability to manage home directories on most OSs (unless you are relying on LDAP for your user DB), but it's not clear to me what management, if any, you might want there. This is where my confusion over what you mean about renaming accounts comes most to bear. John -- 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.
