Reputation: 430
I defined some variables in my defined type remote_file
.
When I instantiate this type in class cdnlog::base
, if I commented the line with require_dir
, I get some error message in puppet client:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid relationship: File[cdnlog-release] { require => , }, because , doesn't seem to be in the correct format. Resource references should be formatted as: Classname['title'] or Modulename::Classname['title'] (take careful note of the capitalization).
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
My manifest:
define remote_file($remote_location=undef, $path=undef, $mode='0644', $require_dir=undef){
exec{"retrieve_${title}":
command => "/usr/bin/wget -q ${remote_location} -O ${path}",
creates => $path,
}
$require_exec="Exec[retrieve_${title}]"
if $require_dir {
$require_file="File[$require_dir]"
}
elsif $require_dir == undef {
$require_file=","
}
file{$title:
path => $path,
mode => $mode,
require => [$require_exec, $require_file],
}
}
class cdnlog::base{
tag 'cdnlog'
file {'/etc':
ensure => directory,
recurse => true,
}
file {'/etc/rc.d/init.d':
ensure => directory,
recurse => true,
}
file {'/etc/cdnlog.d':
ensure => directory,
recurse => true,
}
###########################################
###########################################
###########################################
remote_file {'cdnlog-release':
path => '/etc/cdnlog.d/cdnlog-release',
remote_location => "${collectd_server}/tarball/cdnlog-release",
require_dir => '/etc/cdnlog.d',
}
remote_file {'cdnlog.conf':
path => '/etc/cdnlog.conf',
remote_location => "${collectd_server}/tarball/cdnlog.conf",
require_dir => '/etc',
}
}
thanks for your help
Upvotes: 0
Views: 2863
Reputation: 8223
Adding a refactor to Raul's great answer, for posterity.
file { $title:
path => $path,
mode => $mode,
}
if $require_dir {
File[$title] { require => [ $require_exec , File["$require_dir"] ]
}
elsif $require_dir == undef {
File[$title] { require => $require_exec }
}
It saves you from juggling too many unnecessary variables.
Upvotes: 0
Reputation: 3806
Your efective resource after variable substitution is:
file{'cdnlog-release':
path => '/etc/cdnlog.d/cdnlog-release',
mode => '0644',
require => [Exec['retrieve_cdnlog-release], ","],
}
That is not valid. You should try using
$require_exec=Exec["retrieve_${title}"]
if $require_dir {
$requirearray=[$require_exec ,File["$require_dir"]]
}
elsif $require_dir == undef {
$requirearray=$require_exec
}
file{$title:
path => $path,
mode => $mode,
require => $requirearray,
}
Quotes should be placed inside brackets, too
Upvotes: 3