Pergunta

New puppet user, trying to wrap my head around name spaces and so forth.

I am currently working on a module called user. It has a unixuser class and a unixgroup class in unixuser.pp and unixgroup.pp. I'll limit my question to the creation of users.

init.pp currently only contains:

class user {
  class {'user::unixuser': }
  class {'user::unixgroup': }

  # Create groups before creating users
  Class['user::unixgroup'] -> ['user::unixuser']
}

In unixuser.pp and unixgroup.pp I only want to define the virtual resources. The functions that do this should be in functions.pp for readability.

Question 1: Should functions.pp should only contain definitions or should the definitions sit inside a class? So in code, should functions.pp contain this:

class user::functions {
  define login ($uid, $gid) {
    user { $title:
      ensure  => present,
      uid     => $uid,
      gid     => $gid,
    }
  }
}

Or should define login not be in the user::functions class? If so, should the define line be define user::login or something else?

Going further, unixuser.pp will then contain something similar to the following (incomplete) stanza:

class user::unixuser {
  @something { 'admin':
    uid => 1000,
    gid => 1000,
  }
}

If all of this is finished then I will realize the users from nodes.pp with something like realize User::Something['admin'].

Question 2: How should the class user::unixuser be made aware of the login function? Is this done by having class user::unixuser inherits user::functions or should I have include user::functions or class {'user::functions': } or...?

Question 3: Based on question 2, what comes in the place of @something when the user::unixuser class plays nicely with functions.pp?

I tried to formulate the question to the best of my abilities but if it is still a bit chaotic I apologize. :)

Foi útil?

Solução

First off if a user is assigned to a group that group is auto required, so you shouldn't need the following,:

  # Create groups before creating users
  Class['user::unixgroup'] -> ['user::unixuser']

functions.pp looks fine try the following in init.pp:

class user {
  include user::functions
  include user::unixgroup
  include user::unixuser
}

and unixuser.pp:

class user::unixuser {
  login { 'admin':
    uid => 1000,
    gid => 1000,
  }
  ...
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top