On Thursday, May 7, 2015 at 5:17:22 AM UTC-5, Alfredo De Luca wrote: > > 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? > >
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 -- 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+unsubscr...@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.