Re: Host groups config in puppet & User Management.

Digant C Kasundra
Sat, 29 Sep 2007 06:22:48 -0000

--On Friday, September 28, 2007 6:24 PM -0700 Deepak Naidu
<dnaidu@silverspringnet.com> wrote:

> define user_homedir ($group, $fullname)
>
> {
>
>  user { "$name":
>
>             ensure => present,
>
>             comment => "$fullname",
>
>             gid => "$group",
>
>             groups => $ingroups,
>
>             membership => minimum,
>
>             shell => "/bin/bash",
>
>             home => "/home/$name",
>
>        }
>
>
>
>   exec { "$name homedir":
>
>             command => "/usr/sbin/useradd $name; /bin/cp -R
/etc/skel
> /home/$name; /bin/chown -R $name:$group /home/$name",
>
>             creates => "/home/$name",
>
>             require => User[$name],
>
>        }
>
> }

That''s an interesting approach.  The user type actually uses useradd so
the
exec is only necessary to copy the skel files, and even that isn''t
necessary if you define the home dir and require it so that it exists:

define user_homedir ($group, $fullname) {
    file ( "/home/$name": ensure => directory }
    user { "$name":
        ...
        require => "/home/$name"
    }
}

You would actually want to to specify in file that the owner is the user
but that means it won''t work on the first run since the user
isn''t created
yet, which is a problem (I wish puppet''s internal user add created the
directory, but it doesn''t use the call that create a dir if it
doesn''t
exist).

Generally, you want to avoid using execs, b/c "the Puppet way" is to
not
expose or rely on the underlying mechanics of how to manage the system, but
to represent in the abstract manner of the puppet manifest.