Feature #15718
$name var should be resource name systematicaly
| Status: | Duplicate | Start date: | 07/30/2012 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% | |
| Category: | - | |||
| Target version: | - | |||
| Affected Puppet version: | Branch: | |||
| Keywords: | name title var class resource | |||
Description
Here is an extract of the documentation:
Defined types have a number of built-in variables available, including $name and $title, which are set to the title of the resource when it is declared. (The reasons for having two identical variables with this information are outside the scope of this document, and these two special variables cannot be used the same way in classes or other resources.) As of Puppet 2.6.5, the $name and $title variables can also be used as default values for parameters
This is very nice. But the fact that it’s not the case for something else than defined resource is counter intuitive. For example, I tried
file { ["test1","test2"]:
ensure => present,
content => "test",
path => "/tmp/$name",
}
That doesnt work, because $name is replaced by ‘main’, the class’s name containing this test:
Cannot alias File[test2] to ["/tmp"] at /home/rgarrigu/xtreemOS/vagrant/manifests/xtreemos-devel.pp:25; resource ["File", "/tmp"] already defined at /home/rgarrigu/xtreemOS/vagrant/manifests/xtreemos-devel.pp:25
I had to do this to get it to work:
define myfile {
file { $name:
ensure => present,
content => "test",
path => "/tmp/$name",
}
}
myfile { ["test1","test2"]: }
Agreed, the workaround is not that hard or ugly. But imho $name/title behing defined as the first container name would be far more intuitive.
Related issues
History
#1
Updated by eric sorenson 10 months ago
- Status changed from Unreviewed to Duplicate
Thanks Rémy, I agree — this is a duplicate of an old bug that deserves attention: #5259