Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm starting to use puppet to manage a couple of servers and I'm not sure how to achieve the following.

I've got a users module which I use to create common users across all servers. I've got a git module which I use to install git and set up a system-wide config in /etc/gitconfig. What I'd like to do is:

  1. On servers which are configured to install git (not all of them), go and drop a (templated) .gitconfig into the home directories of all existing users. And obviously manage this for changes to the template.
  2. Add the .gitconfig for all future users. But I don't feel this belongs in the users module - I think it belongs in the git module. It feels like I want to know when any user has been added (not just a given instance of user), and then be able to access the parameters of that user creation (e.g. home directory, real name and username).

Essentially, part 2 would be easy if I just deployed a templated .gitconfig to all users created by the users module. But I don't really want users to have a .gitconfig file if git isn't installed on the system. So what I'm really trying to say is "for all managed users on this system, if git is installed, manage a .gitconfig file".

Thanks!

share|improve this question

4 Answers 4

Yo will need to use two procedures , first for already created accounts :

http://www.cyberciti.biz/tips/linux-unix-shell-batch-copy.html

and another one for future users :

http://linuxers.org/howto/how-set-default-content-new-users-home-directory-using-etcskel

share|improve this answer
    
Well, I could build the whole management using shell scripts! I was hoping to leverage the power of Puppet to achieve something simple here. Regarding /etc/skel, I need to be able to template the .gitconfig on various details of the user being created (e.g. username, etc.) so this won't work. –  dty Dec 11 '11 at 0:10

It'll be easier if users and nodes that need to have git are managed by puppet:

class git {
  packakge { "git":
    ensure => installed,
  }
}

class users {
  user { ... }
  file { "/home/${user}/.gitconfig":
    ensure => present,
    content => template("gitconfig"),
    require => Class["git"],
  }
}

Then for each git node, include class git.

share|improve this answer
    
I'm still new to puppet, but my reading of this is that as soon as I start to use that class to manage users, my servers will all get git installed on them due to the require meta-attribute. This is not what I want. I want to pick and choose which servers get git, and only manage the .gitconfig file for managed users on servers where I have chosen to also install git. –  dty Dec 11 '11 at 12:34
    
Well, it was just an example. You can subclass your users so that you have sysadmin users, git users, dba users, etc. –  James O'Gorman Dec 11 '11 at 12:46
    
I know. But none of that really relates to the actual question, I'm afraid. –  dty Dec 11 '11 at 17:34
    
If you really want to detect if git is on a machine, you'll have to write your own facts for facter which is a chapter of a book on its own. You may want to get a copy of Pro Puppet which is on sale at the moment. –  James O'Gorman Dec 11 '11 at 18:25

for all managed users on this system,

So you either have to define this on the users module, or export a virtual resource from it. Given the usage, I don't see a way to do it with virtual resources.

if git is installed,

Strictly speaking, create a custom fact to check if it is installed. For example:

# git.rb
Facter.add("git") do
        setcode do
                %x{/usr/bin/test -x /usr/bin/git && /bin/echo yes || /bin/echo no}.chomp
        end
end

On the other hand, the git module could export a virtual resource, such as the .gitconfig file, and the user module could realize it. I don't think it is possible to realize the same resource in a parameterized (user's home directory) way.

manage a .gitconfig file

Well, that you know how to do.

share|improve this answer

If you want to just ensure a base file, use tags. The virtual file resource will only get realized if the git class has been included. You could set this up with a template to add in the user name and email. This can cause problems if users want to customize their git config though (puppet will overwrite their changes).

class git {
   @file { 'git_user_config':
     tag     => 'git_user_config',
     path    => '/tmp/.gitconfig',
     content => template("git/gitconfig.erb"),
     require => Package["git"],
  }
}

class user {
  # user defs here

  File <| tag == 'git_user_config' |> {
    path => "/home/${user}/.gitconfig",
  }
}

You may also be able to leverage the puppet-stdlib (https://forge.puppetlabs.com/puppetlabs/stdlib) getparam feature.

Untested code, not sure if this would work. Generally I like the tagged virtual resources a lot.

class users {
  user {...}

  if ( (defined(Package['git']) && (getparam(Package['git'],'ensure') == 'present') ) {
    file {
      "/home/${user}/.gitconfig":
        ensure => present,
        content => template("git/gitconfig.erb"),
        require => Class["git"],
    }
  }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.