On Dec 18, 2006, at 5:36 PM, Charlie Schluting wrote:
> I tried using $name in this manner:
>
> remotefile { "/etc/auto_direct.local":
> mode => 644,
> source => "solall/$name"
> }
>
> (The remotefile function is handy, BTW)
>
> When I use $name here, instead of specifying the actual path to the
> file (solall/etc/auto_direct.local), puppetd ends up making
> /etc/auto_direct.local an empty directory.
>
> Shouldn''t $name just expand to the string
"/etc/auto_direct.local" and
> work the way I expect? :)
No, because $name is bound to the calling block, not the block inside
remotefile.
Imagine this code:
remotefile { "/path/to/$name": source => "/nfs/$name" }
Clearly the $name in the name cannot be bound to the name itself;
instead, $name is looked up in the current, calling block (i.e.,
whatever class or definition is calling ''remotefile'').
In cases where you want to do this, you should create a
''sourcebase''
parameter, something like the following:
define remotefile($sourcebase = false, $source = false) {
if $source { $realsource = $source }
else {
if $sourcebase { $realsource = "$sourcebase/$name" }
else { fail("You must provide a source or a sourcebase")
}
file { $name:
source => $source
}
}
I haven''t verified that exactly this works (in particular, I
don''t
use ''if/else'' very much), but you should get the basic idea:
The
caller should either provide an explicit source, which will be used
directly, or a sourcebase, which will have $name (inside the
remotefile block) appended.
--
Good judgment comes from experience, and experience comes from bad
judgment. --Barry LePatner
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com