Puppet node inheritance is not the same as inheritance in most other programming languages . Included classes are evaluated immediatelly when the child is evaluated. And the parent node is evaluated after that. Therefore my example will never work. If you want to know recommended solution for this, read puppet - common misconceptions. I did it this way and it works.
Although I have to admit that I'm pretty disappointed right now, because complex puppet syntax might be confusing for starters.
Two things regarding your puppet code.
The define should be in it's own file (named add_user.pp, and located in the <modulename>/manifests/
folder) , rather than in the class file.
Set the define up (change $name to $username, as $name is a reserved variable), and then add the same set of parameters as the define uses to the class. (which in your example would be $modulepath/users/manifests/add.pp
to make it work with the autoloader)
If you change the class as follows:
class users::add( $u_name, $u_comment, $u_home, $u_shell, $u_uid, $u_gid, $u_password)
{
users::add_user{ $u_name:
$username => $u_name,
$comment => $u_comment,
$home => $u_home,
$shell => $u_shell,
$uid => $u_uid,
$gid => $u_gid,
$password => $u_password,
}
}
And change the site.pp to:
import "classes/*.pp"
node default{
class { 'add_user':
username => "saga",
comment => "Arun Sag",
gid => "100",
home => "/home/saga",
password => '$1$passwordhash/',
shell => "/bin/bash",
uid => "70960",
}
}
For the yaml, something like this will do it, please refer to the documentation for more details:
---
classes:
users::add:
parameters:
name: some_name
comment: some_comment
home: home_value
shell: /bin/sh
uid: 3990
gid: 3990
password: superstrongpassword
environment:
production
Best Answer
Defined classes does mean that the class is included. Just to be clear, the
<% if broadcast ...
bit is not the way to check the inclusion of the broadcast class, but rather to syntax of a conditional using the value of the broadcast variable, the classes array contains the names of all the defined classes.This would be how you would check for the mod_security class for instance:
Edit:
Whoops...the method is called include? not includes?. Fixed above.