Puppet manage HOMES on Desktop Computers

94 views
Skip to first unread message

Rafael Cristaldo

unread,
Feb 10, 2014, 9:15:24 AM2/10/14
to puppet...@googlegroups.com
Hi All!

Has anybody already needed to manage HOMES on desktops computers with puppet ?

I have create a class to manage the /etc/skel directory...so the problem is that after thet the user loggin ... the home has been created em copied all /etc/skel files..

But NOW i need to put another LINK for exemplo....

The class create the new LINK at /etc/skel ...but how to create the link into /home/$USER ??

I have more than 500 computers... and they are into a Domain Controller with samba and winbind and LDAP.

With shell script is something like this:

###########################################################

#/bin/bash
for i in /home/*
do
if [ -d "$i" ]
then

touch    $i/Desktop/teste.txt
fi
done

############################################################

This works fine..but how to create this like a class in PUPPET?

Thanks!!

Joseph Swick

unread,
Feb 10, 2014, 11:08:05 AM2/10/14
to puppet...@googlegroups.com
On 02/10/2014 09:15 AM, Rafael Cristaldo wrote:
> Hi All!
>
> Has anybody already needed to manage HOMES on desktops computers with
> puppet ?
>
> I have create a class to manage the /etc/skel directory...so the problem is
> that after thet the user loggin ... the home has been created em copied all
> /etc/skel files..
>
> But NOW i need to put another LINK for exemplo....
>
> The class create the new LINK at /etc/skel ...but how to create the link
> into /home/$USER ??

<trim>
>
> This works fine..but how to create this like a class in PUPPET?
>
> Thanks!!
>

I'm not sure if our use case is similar to yours or not. However, I
added the following to our user management module to ensure that the
user's home directory regardless of how it's created or managed, has all
the appropriate files from the local system's /etc/skel. The 'touch
/dev/null' is so that don't have to do "provider => 'shell'," in the
exec (which we had a reason for at the time, but I'm not recalling it
right now):

#Copy base profile from /etc/skel, update only but make backup if we
happen to overwrite an existing file
#Made as portable as possible because CentOS 5 doesn't support the
'-n' option for cp.
exec {"${username}_copy_skel":
command => "touch /dev/null; for i in `ls -A /etc/skel`; do /bin/cp
-R -u --backup=numbered /etc/skel/\$i ${homedir_real}; done; /bin/chown
-R ${username}:${username} ${homedir_real}",
unless => "test \"\$(j=0;for i in `ls -A /etc/skel`; do test -e
${homedir_real}/\$i; if [ \"\$?\" -ne \"0\" ]; then j=1;fi; done;echo
\$j)\" = \"0\"",
}

It may not be all that efficient for a system that has a lot of users on
it. Hope that helps.

--
Joseph Swick <joseph...@meltwater.com>
Operations Engineer
Meltwater Group

signature.asc

Rafael Cristaldo

unread,
Feb 10, 2014, 12:09:16 PM2/10/14
to puppet...@googlegroups.com
Hi Joseph Swick !

Thanks for the answer !

This really can help me! .. but thereis some questions about your manifest.

Did you build custom factes for ${username} and ${homedir_real} ? Or you propose to edit it and change this values to the real Username and Homdir ?

This is really a very valid option to keep both directories (/etc/skel and /home/USER) with same files...but it does not REMOVE files from the HOME directory that i don't need anymore, just remove from /etc/skel

Anyway thanks for your help.

Joseph Swick

unread,
Feb 10, 2014, 1:03:15 PM2/10/14
to puppet...@googlegroups.com
On 02/10/2014 12:09 PM, Rafael Cristaldo wrote:
> Hi Joseph Swick !
>
> Thanks for the answer !
>
> This really can help me! .. but thereis some questions about your manifest.
>
> Did you build custom factes for ${username} and ${homedir_real} ? Or you
> propose to edit it and change this values to the real Username and Homdir ?

Sorry, I should have pointed out that those are parameters/variables in
our custom module. For $homedir_real, it takes homedir as an optional
parameter, if it's not set, then it uses a default based on the
username, then assigns it to $homedir_real. If $homedir is set, then it
gets assigned to $homedir_real.

For $username, that's taken from the title of the define for actually
creating the users in our user management module as we're managing users
from within Puppet. After re-reading your original message, I noticed
that you stated you're managing users from LDAP, so I'm not sure if this
is something you could easily incorporate into puppet to take care of,
unless it's a custom script that you push out via puppet and create a
cronjob for.


> This is really a very valid option to keep both directories (/etc/skel and
> /home/USER) with same files...but it does not REMOVE files from the HOME
> directory that i don't need anymore, just remove from /etc/skel

Unfortunately no, it won't clean up anything that's been removed from
/etc/skel, only update user's home directories with new items in there.
But that's likely due to our different use case.


> Anyway thanks for your help.
>


signature.asc

Rafael Cristaldo

unread,
Feb 10, 2014, 3:24:00 PM2/10/14
to puppet...@googlegroups.com
Well, for now I still can not manage HOMES users, as I would like, but I could manage the user who is logged tty7. With this I can apply a class in the User's Node and manipulate your home/Desktop, /home/Documents etc.

I created a custom fact to identify which user is logged in at the time and so I could add and remove files from your Desktop, fixing permissions.

I looked for facts that show the user in tty7 e did't found it!!

My custom fact

who.rb

mkdir -p /etc/puppet/modules/myfacts/lib/facter/who.rb

cat /etc/puppet/modules/myfacts/lib/facter/who.rb
require 'facter'
Facter.add("who") do
  setcode do
     %x{who |egrep 'tty7' | cut -d ' ' -f1}.chomp
  end
end

After that I exported the RUBYLIB

export RUBYLIB=/etc/puppet/modules/myfacts/lib

Now test the custom fact!
# facter who
rafael

This is a Class of example:

who.pp

file    {'link':
    path    => "/home/${who}/Desktop/link.txt",
    ensure    => present,
    owner    => "${who}",
    group    => "${who}",
    mode    => 0660,
    #source    => '/tmp/link.txt',
    content    => "\n O custom facter WHO funcionou!",
    }

All Right!! ..there is my file on Desktop!! It works!

Any help with this implementation ?


Reply all
Reply to author
Forward
0 new messages