[Puppet Users] Re: Creating user with random password (only once)

mukulm
Thu, 09 Feb 2012 13:43:50 -0000

Also how can I use owner be set other than root as,

owner =>  ?   ( want to set user as $USER  )
group => ?     ( want to set group as GROUP  )
ensure => present,

Thanks
Mukulm


On Feb 9, 12:30 am, wernerbahlke <werner.bah...@gmail.com>
wrote:
> Hi,
>
> I want to create a user with a random password. Is there a way to only
> execute the manifest once when the user does not exist but not once
> the user is created?
>
> I know how to create a random password and can use generate to execute
> this function (or make it a custom fact provided I get this fact
> executed).
>
> So far I call an add_user method define in a users module out of my
> base class. Here is the code:
>
>   include users
>
>   users::add_user { ''testuser'':
>     name     => ''testuser'',
>     uid      => ''777'',
>     password => generate(''/usr/local/bin/new_hash''),
>     shell    => ''/bin/csh'',
>     groups   => ''testuser'',
>   }
>
> But alas this will get executed every time the client runs since the
> password will have changed due to the new generate call.
>
> One work-around I could think of is to create the user on the client
> (FreeBSD) using an exec calling the makepassword and pw command.
>
> Then I could check for existance of the user in the masterpasswd file
> with an unless check.
>
> But I much prefer do this with Puppet natively.
>
> Any suggestions will be greatly appreciated.
>
> Werner