check if user exist

1,907 views
Skip to first unread message

Alfredo De Luca

unread,
May 7, 2015, 6:17:22 AM5/7/15
to puppet...@googlegroups.com
Hi all.
I am using puppet source with Hiera. I want to manage users but also I
want to check if an user exist before doing something else and create
it.

I have a module prousers as follow:

prousers/init.pp
class prousers {
create_resources(user, hiera_hash('pro_user'))
}


then from hiera

common.yaml
pro_user:
bla1:
ensure: 'present'
comment: 'bla bla 1'
managehome: 'true'
uid: '1579'
bla2:
ensure: 'present'
comment: 'bla bla 2'
managehome: 'true'
uid: '1014'


How can I check in the prousers module if an user exist or other checks?

Any info would be appreciated.

Regards

--
Alfredo

jcbollinger

unread,
May 7, 2015, 9:32:28 AM5/7/15
to puppet...@googlegroups.com
If you want to condition parts of a node's catalog on whether a given user exists, then
  1. the condition must be based on the system's state at the time of the catalog request (not during catalog application), and
  2. you would accomplish it by writing a custom fact to probe that user's existence and provide that information to the master.
HOWEVER, it's unclear whether that's really what you want.  If the objective is to check whether user 'pro_user' exists so that you can create him if he's not already present, then that's an ineffective way to use Puppet.  If the point is that any node having class prousers should have all the users specified in the Hiera data, then natural way to approach it is to simply declare all those users.  As with any other resource type, Puppet examines the current state of each declared user (including whether he exists at all), and performs exactly those actions needed to bring the node to the target state expressed in its catalog -- no more, no less.

If you want to be sure that other resources are managed only after the users have been put in the desired state, then that is the purpose of resource relationships.


John

Alfredo De Luca

unread,
May 8, 2015, 12:22:43 AM5/8/15
to puppet...@googlegroups.com

Hi John.
I am aware that if I say userxx ensure is present will work but what I want is the first time create the user aNd set a default password but then when the user changes it own pass I just wanna check if is present and not resetting the password.

/Alfredo

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2348ab8f-a814-4593-894e-7e343e52018c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
May 8, 2015, 9:11:22 AM5/8/15
to puppet...@googlegroups.com


On Thursday, May 7, 2015 at 11:22:43 PM UTC-5, Alfredo De Luca wrote:

Hi John.
I am aware that if I say userxx ensure is present will work but what I want is the first time create the user aNd set a default password but then when the user changes it own pass I just wanna check if is present and not resetting the password.


Then as I said, create and use a custom fact to evaluate the user's existence prior to the catalog request.  Also, consider configuring agents to not apply cached catalogs.

You could perhaps create a custom provider for the User type, too, to perform the evaluation at the time of application.  That could work to achieve the behavior you describe, but it will probably produce anomolies in the form of reported updates to the affected user(s) that in fact change nothing.


John

Eric Sorenson

unread,
May 11, 2015, 8:28:22 PM5/11/15
to puppet...@googlegroups.com, john.bo...@stjude.org
The canonical way to do this is like this:


There's an open feature request here: https://tickets.puppetlabs.com/browse/PUP-1331

Feel free to add yourself as a watcher and add a comment describing your use case, those help bugs bubble up to the top.

Alfredo De Luca

unread,
May 12, 2015, 5:04:31 PM5/12/15
to puppet...@googlegroups.com, john.bo...@stjude.org

Thanks so much Eric.
Really appreciated. 

/Alfredo

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages