Resources in Puppet have to be unique, i. e. have to have a unique name.
In the described case, you had the resource Exec["sleep 5"]
in your definition and every time you call srv
(it's basically the same as including a parameterized class), the resource Exec["sleep 5"]
will also be included and thus the parser finds two or more resources with the same name.
By appending the $name
of the definition to the name of your Exec
resource, you make it unique. Well, at least most likely unique since when you have another resource with the same name (Exec["sleep 5 for foo"
) somewhere else in your manifests, you'll run into this error again.
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
I would change your template to have something like:
Also make sure that in your vlan.pp you have something of the sort:
The template will have whatever variables are accessible in the scope of where the template was generated. An easy way to make sure a variable is accessible in the template is to turn any variables from outside the local scope into an instance variable with something like this:
Then you access the var in your template with @var.