[Puppet Users] can not use $caller_module_name

flex
Sat, 12 Feb 2011 17:06:32 -0000

This is my puppet script:

modules/redarrow/manifests/add.pp:

define redarrow::add($type = "file") {
    file { "/etc/redarrow.conf/$name.conf":
        owner => "root",
        group => "root",
        mode => 644,
        source => $type ? {
            "file" =>
"puppet:///modules/$caller_module_name/redarrow.conf",
            default => undef,
        },
        content => $type ? {
            "template" =>
template("$caller_module_name/redarrow.erb"),
            default => undef,
        },
    }
}

modules/portage/manifests/init.pp:

redarrow::add {test_portage: }

Result:
(/Stage[main]/Portage/Redarrow::Add[test_portage]/File[/etc/redarrow.conf/test_portage.conf])
Could not evaluate: Error 400 on SERVER: Invalid module name; module names
must be alphanumeric (plus ''-''), not
''redarrow.conf'' Could not retrieve file
metadata for puppet:///modules//redarrow.conf: Error 400 on SERVER: Invalid
module name; module names must be alphanumeric (plus ''-''), not
''redarrow.conf'' at
/home/flex/puppet/modules/redarrow/manifests/add.pp:14

It seems that the variable $caller_module_name is not set, then i found
another stange thing, i got what i want like this:

define redarrow::add($module = $name, $type = "file") {
    file { "/etc/redarrow.conf/$name.conf":
        owner => "root",
        group => "root",
        mode => 644,
        source => $type ? {
            "file" =>
"puppet:///modules/$module/redarrow.conf",
            default => undef,
        },
        content => $type ? {
            "template" =>
template("$module/redarrow.erb"),
            default => undef,
        },
    }
}

the $name in varaible list of the define is not the same as the $name below
which is the resource name, it is this a bug or a hidden feature?