On Fri, Jul 31, 2009 at 3:43 AM, David Schmitt<da...@dasz.at> wrote: > > Asif Iqbal wrote: >> On Wed, Jul 29, 2009 at 1:57 AM, David Schmitt<da...@dasz.at> wrote: >>> Asif Iqbal wrote: >>>> So I think I should start small and simple and it may grow to a >>>> solution that will be really useful to others. >>>> >>>> Lets start w/ real basic. >>>> >>>> I have 300 hosts. I like a push a user to about 100 hosts (dns >>>> resolver type hosts) out of 300 total. >>>> >>>> How do I set that up within puppet ? >>> The very simplest stuff: >>> >>> | node "dns1", ..., "dns100" { >>> | user { "foo": ... } >>> | } >> >> I tried to expand on it and I have setup a recipe which is not really >> working yet >> >> node basenode { >> $userlist = [ "user1", "user2", "user3", .. , "user50" ] >> $passwd = [ "hashkey1", "hashkey2", .. , "hashkey50" ] >> $fullname = [ "fname1 lname1", "fname2 lname2",... , "fname50 lname50" ] >> $uids = [ "101", "102", ... , "150" ] >> user { $userlist: >> ensure => "present", >> uid => $uids, >> gid => "1", >> comment => $fullname, >> home => "/export/home/$userlist", >> password => $passwd, >> shell => "/bin/bash", >> managehome => "true", >> } >> } > > That's not how it is intended to work. You'll need to create a define to > handle such "parallel" arrays: > > define custom_user($passwd, $fullname) { > user { "user${name}": > ensure => present, > uid => 100 + $name, > gid => 1, > comment => $fullname, > home => "/export/home/${name}", > password => $passwd, > shell => "/bin/bash", > managehome => true, > } > } > > custom_user { > "1": > passwd => "hashkey1", > fullname => "fname1 lname1"; > "2": > passwd => ... > }
Here is my updated recipe #site.pp class newuser { define newu ( $uid , gid = 1, $fullname ) { exec { "/usr/sbin/useradd -m -d /home/$name -c $fullname -u $uid -g $gid -s /bin/bash $name": } } define newid ( $uid , gid = 1, $passwd, $fullname ) { user { $name: ensure => present, uid => "$uid", gid => "$gid", comment => "$fullname", home => "/export/home/$name", password => "$passwd", shell => "/bin/bash", managehome => "true", } } define addgrp ( $groups ) { exec { "/usr/sbin/usermod -G $groups $name": } } } newuser::newu { "testuser": uid => "102", gid => "1", fullname => "test user", } newuser::newid { "testu2": uid => "103", gid => "10", passwd => "XyZ123ZyX12", fullname => "test2 user2", } newuser::addgrp { "testu2": groups => ["sysadmin", "developer"] } node basenode { include newuser } node default inherits basenode {} It worked somewhat. The group names "sysadmin" and "developer" became one group "sysadmindeveloper" I was trying to use the groups array to call the addgrp definition multiple times. Also it failed to create user `testuser' using Newuser::Newu deatils here debug: Loaded state in 0.00 seconds debug: //Newuser::Newid[testu2]/User[testu2]: Changing ensure debug: //Newuser::Newid[testu2]/User[testu2]: 1 change(s) debug: User[testu2](provider=user_role_add): Executing '/usr/sbin/useradd -u 103 -s /bin/bash -g 10 -c test2 user2 -d /export/home/testu2 -m testu2' notice: //Newuser::Newid[testu2]/User[testu2]/ensure: created debug: //Newuser::Addgrp[testu2]/Exec[/usr/sbin/usermod -G sysadmindeveloper testu2]: Changing returns debug: //Newuser::Addgrp[testu2]/Exec[/usr/sbin/usermod -G sysadmindeveloper testu2]: 1 change(s) debug: //Newuser::Addgrp[testu2]/Exec[/usr/sbin/usermod -G sysadmindeveloper testu2]: Executing '/usr/sbin/usermod -G sysadmindeveloper testu2' debug: Executing '/usr/sbin/usermod -G sysadmindeveloper testu2' err: //Newuser::Addgrp[testu2]/Exec[/usr/sbin/usermod -G sysadmindeveloper testu2]/returns: change from notrun to 0 failed: /usr/sbin/usermod -G sysadmindeveloper testu2 returned 3 instead of 0 at /etc/puppet/manifests/site.pp:22 debug: //Newuser::Newu[testuser]/Exec[/usr/sbin/useradd -m -d /home/testuser -c test user -u 102 -g 1 -s /bin/bash testuser]: Changing returns debug: //Newuser::Newu[testuser]/Exec[/usr/sbin/useradd -m -d /home/testuser -c test user -u 102 -g 1 -s /bin/bash testuser]: 1 change(s) debug: //Newuser::Newu[testuser]/Exec[/usr/sbin/useradd -m -d /home/testuser -c test user -u 102 -g 1 -s /bin/bash testuser]: Executing '/usr/sbin/useradd -m -d /home/testuser -c test user -u 102 -g 1 -s /bin/bash testuser' debug: Executing '/usr/sbin/useradd -m -d /home/testuser -c test user -u 102 -g 1 -s /bin/bash testuser' err: //Newuser::Newu[testuser]/Exec[/usr/sbin/useradd -m -d /home/testuser -c test user -u 102 -g 1 -s /bin/bash testuser]/returns: change from notrun to 0 failed: /usr/sbin/useradd -m -d /home/testuser -c test user -u 102 -g 1 -s /bin/bash testuser returned 2 instead of 0 at /etc/puppet/manifests/site.pp:5 debug: Finishing transaction 74491050 with 3 changes debug: Storing state debug: Stored state in 0.02 seconds notice: Finished catalog run in 0.41 seconds > > See > http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#definitions > for details on definitions. > > > Regards, DavidS -- Asif Iqbal PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---