multiple user creation with puppet module .

385 views
Skip to first unread message

Krushna Chandra Sahu

unread,
Dec 18, 2014, 8:20:32 PM12/18/14
to puppet...@googlegroups.com
Hi I am beginner in puppet world . I just created a module folder called users with following folder .

puppetservertest:/etc/puppet/modules/users# ls
files  manifests  templates

In manifest folder, I have single file called  init.pp

class users (

)

{
        group { "nextadmin":
                ensure => present,
        }

define users::add ( $username , $groupname = "" , $shell = "",  $ensure  , $login =  )  {
        user { "$username":
                ensure => "$ensure" ,
                groups => "$groupname"  ,
                shell =>  "$shell" ,
                require => Group["nextadmin"]  ,
        }
}
}


Now to I have to create multiple user . Where and how to declare the username ,groupname etc in the same file ?


Felix Frank

unread,
Dec 23, 2014, 7:35:15 PM12/23/14
to puppet...@googlegroups.com
Hi,

welcome to the list then.

On 12/19/2014 02:20 AM, Krushna Chandra Sahu wrote:
> In manifest folder, I have single file called init.pp
>
> class users (
>
> )
>
> {
> group { "nextadmin":
> ensure => present,
> }
>
> define users::add ( $username , $groupname = "" , $shell = "",
> $ensure , $login = ) {
> user { "$username":
> ensure => "$ensure" ,
> groups => "$groupname" ,
> shell => "$shell" ,
> require => Group["nextadmin"] ,
> }
> }
> }
>

First off, the define ... { } block should not be nested in the class
users { ... } block.

Create a manifests/add.pp file that holds only the define.

Verbs like "add" are misleading resource type names, for they imply an
action. You seldomly define actions in Puppet manifests. Instead, you
declare *state* that Puppet will manage for you. I suggest you go for
users::user or users::instance instead.

>
> Now to I have to create multiple user . Where and how to declare the
> username ,groupname etc in the same file ?

Once you have structured the manifests in a suitable fashion (as
described above), you can put this in a node { } block or any other
suitable manifest location:

users::user {
'jack':
ensure => present,
username => 'jack',
groupname => 'admins',
shell => '/bin/bash',
}
users::user {
'jill':
ensure => present,
username => 'jill',
groupname => 'operators',
shell => '/bin/bash',
}

HTH,
Felix
Reply all
Reply to author
Forward
0 new messages