|
|
Subject: [Puppet Users] Re: Creating Multiple Users using 'define' - msg#00068
I use this like this
--(saurabh.ve@puppet)-(~/puppet/modules/users/manifests)--
--(0)> cat init.pp
class users::common
{
group { "t-sysad":
ensure => present,
}
@file { "/etc/sudoers":
owner => root,
group => root,
mode => 440,
source => [ "puppet:///users/$project/sudoers.$hostname" ,
"puppet:///users/$project/sudoers" ,
"puppet:///users/sudoers.$hostname" ,
"puppet:///users/sudoers" ,
]
}
}
define users::add ( $username , $groupname = "" , $shell = "",
$password = "" , $ensure , $login = false ) {
user { "$username":
ensure => "$ensure" ,
groups => "$groupname" ,
shell => "$shell" ,
password => "$password",
require => Group["t-sysad"] ,
}
if $login != false {
file { "/home/$username" :
ensure => directory ,
mode => 644 ,
owner => $username ,
group => $username ,
before => [ File["/home/$username/.ssh"] ,
File["/home/$username/.ssh/authorized_keys"] ,
File["/home/$username/.bashrc"] ] ,
}
file { "/home/$username/.ssh" :
ensure => directory ,
mode => 644 ,
owner => $username ,
group => $username ,
}
file { "/home/$username/.ssh/authorized_keys":
ensure => present ,
source =>
"puppet:///users/authorized_keys/$username" ,
mode => 644 ,
require => [ User["$username"] ,
File["/home/$username/.ssh"] ] ,
owner => $username ,
group => $username ,
}
file { "/home/$username/.bashrc":
ensure => present ,
source => [ "puppet:///users/user_bashrc.$username"
,
"puppet:///users/user_bashrc" ] ,
mode => 644,
owner => "$username",
group => "$username",
require => User["$username"] ,
}
}
}
--(saurabh.ve@puppet)-(~/puppet/manifests/production/common/nodes)--
--(1)> cat common_users.pp
class sysad_users
{
include users::common
users::add { "user4": username => "user4" , groupname =>
"t-sysad" , shell => "/bin/bash" , ensure => present , login
=> true }
users::add { "user3": username => "user3" , groupname =>
"t-sysad" , shell => "/bin/bash" , ensure => present , login
=> true }
users::add { "user2": username => "user2" , groupname =>
"t-sysad" , shell => "/bin/bash" , ensure => present , login
=> true }
users::add { "user1": username => "user1" , groupname =>
"t-sysad" , shell => "/bin/bash" , ensure => present , login
=> true }
users::add { "nagios": username => "nagios" , ensure =>
present , login => false }
}
This works fine for me , you can make necessary modification as per
your need .
Thanks
~saurabh
On 11/5/2009 4:48 PM, M.F.Haris wrote:
hi all,
I wanted to create multiple set of users in my client in one go. how to
do it? i tried with 'define' but there is a problem with it.
/modules/functions/usermanagement.pp
----------------------------------------------------------
define createUsers($username, $group, $home, $host)
{
$sshDir = ".ssh"
$pub_key = "id_rsa.pub"
realize(
Group[$group],
User[$username],
)
file { "${home}/${username}":
ensure => directory,
owner => $username,
group => $group,
mode => 750,
require => User["${username}"],
}
file { "${home}/${username}/${sshDir}":
ensure => directory,
owner => $username,
group => $group,
mode => 700,
require => File["${home}/${username}"],
}
file { "${home}/${username}/$sshDir/authorized_keys":
ensure => present,
owner => $username,
group => $group,
mode => 600,
require => File["${home}/${username}/.ssh"],
source => "puppet:///myfiles/$pub_key.${username}",
}
/modules/functions/staffmanagement.pp
----------------------------------------------------------
class mystaff
{
createUsers{ "realizingUser": # defined function in above file
username => "xxxx",
group => "gggg",
home => "/home",
host => "x.x.x.x",
}
}
It is working for 1 user but calling createUsers for more than 1 user
is not possible with this, Can any one guide me how make it possible.
or if you have the same thing in past please share with me.
Thanks & Regards
M.Haris Farooque
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@xxxxxxxxxxxxxxxx To unsubscribe from this group, send email to puppet-users+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Thread at a glance:
Previous Message by Date:
[Puppet Users] Creating Multiple Users using 'define'
hi all,I wanted to create multiple set of users in my client in one go. how to do it? i tried with 'define' but there is a problem with it./modules/functions/usermanagement.pp----------------------------------------------------------
define createUsers($username, $group, $home, $host){ $sshDir = ".ssh" $pub_key = "id_rsa.pub" realize( Group[$group], User[$username], )
file { "${home}/${username}": ensure => directory, owner => $username, group => $group, mode => 750, require => User["${username}"],
} file { "${home}/${username}/${sshDir}": ensure => directory, owner => $username, group => $group, mode => 700, require => File["${home}/${username}"],
} file { "${home}/${username}/$sshDir/authorized_keys": ensure => present, owner => $username, group => $group, mode => 600, require => File["${home}/${username}/.ssh"],
source => "puppet:///myfiles/$pub_key.${username}", }/modules/functions/staffmanagement.pp
----------------------------------------------------------
class mystaff{ createUsers{ "realizingUser": # defined function in above file username => "xxxx", group => "gggg", home => "/home",
host => "x.x.x.x", }}
It is working for 1 user but calling createUsers for more than 1 user is not possible with this, Can any one guide me how make it possible. or if you have the same thing in past please share with me.Thanks & Regards
M.Haris Farooque
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@xxxxxxxxxxxxxxxx To unsubscribe from this group, send email to puppet-users+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Next Message by Date:
[Puppet Users] Re: Any ideas about this error with upgrading to 0.25.1?
> The error the OP posted comes from the file serving layer, so it's more
> a fileserver.conf issue.
Ok here's my fileserver.conf.
[plugins]
allow 127.0.0.1/32
allow 192.168.10.0/24
allow 192.168.11.0/24
[modules]
allow 127.0.0.1/32
allow 192.168.10.0/24
allow 192.168.11.0/24
Puppet traffic occurs over a private network. This config works with
0.24.8 clients, so why wouldn't it work with 0.25?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
puppet-users+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Previous Message by Thread:
[Puppet Users] Creating Multiple Users using 'define'
hi all,I wanted to create multiple set of users in my client in one go. how to do it? i tried with 'define' but there is a problem with it./modules/functions/usermanagement.pp----------------------------------------------------------
define createUsers($username, $group, $home, $host){ $sshDir = ".ssh" $pub_key = "id_rsa.pub" realize( Group[$group], User[$username], )
file { "${home}/${username}": ensure => directory, owner => $username, group => $group, mode => 750, require => User["${username}"],
} file { "${home}/${username}/${sshDir}": ensure => directory, owner => $username, group => $group, mode => 700, require => File["${home}/${username}"],
} file { "${home}/${username}/$sshDir/authorized_keys": ensure => present, owner => $username, group => $group, mode => 600, require => File["${home}/${username}/.ssh"],
source => "puppet:///myfiles/$pub_key.${username}", }/modules/functions/staffmanagement.pp
----------------------------------------------------------
class mystaff{ createUsers{ "realizingUser": # defined function in above file username => "xxxx", group => "gggg", home => "/home",
host => "x.x.x.x", }}
It is working for 1 user but calling createUsers for more than 1 user is not possible with this, Can any one guide me how make it possible. or if you have the same thing in past please share with me.Thanks & Regards
M.Haris Farooque
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@xxxxxxxxxxxxxxxx To unsubscribe from this group, send email to puppet-users+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Next Message by Thread:
[Puppet Users] Re: Creating Multiple Users using 'define'
On Nov 5, 5:18 am, "M.F.Haris" <mfha...@xxxxxxxxx> wrote:
> hi all,
> I wanted to create multiple set of users in my client in one go. how to do
> it? i tried with 'define' but there is a problem with it.
> define createUsers($username, $group, $home, $host)
> {
> $sshDir = ".ssh"
> $pub_key = "id_rsa.pub"
>
> realize(
> Group[$group],
> User[$username],
> )
> file { "${home}/${username}":
[...]
> file { "${home}/${username}/${sshDir}":
[...]
> file { "${home}/${username}/$sshDir/authorized_keys":
[...]
> class mystaff
> {
> createUsers{ "realizingUser": # defined function in above file
> username => "xxxx",
> group => "gggg",
> home => "/home",
> host => "x.x.x.x",
> }}
> It is working for 1 user but calling createUsers for more than 1 user is not
> possible with this, Can any one guide me how make it possible. or if you
> have the same thing in past please share with me.
It sounds like you may be using the same name for each invocation of
the definition (the "realizingUser" part). The names must be unique.
I don't see you using the $name or $title variables anywhere in the
definition body, so does the name actually have any significance in
your current implementation? You could try rewriting it like this:
# Note: removed the $username parameter
define createUsers($group, $home, $host)
{
realize(
Group[$group],
# Note: $name instead of $username
User[$name],
)
# Declarations of user-associated file resources, etc. ...
}
You would then invoke it like so:
class mystaff
{
# Note: "xxxx" is the username of the user to create
createUsers{ "xxxx":
group => "gggg",
home => "/home",
host => "x.x.x.x",
}
# ...
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
puppet-users+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|