Issue #4780 has been updated by Nico Schottelius.
Summary:
- the error messages are far away from being useful
- If neither content nor source is given, but ensure => present, puppet should
throw an error like "Cannot ensure presence of #{file}, neither content nor
source given"
- After this is fixed, the example one should probably also usable
- example two, passing variables to a define that are not explicitly defined
looks like the usual "convention over configuration way" and seems to be the
way with least effort in writing manifests. This is probably a feature to
implement (can discuss about that)
puppetmaster is 2.6.0-2 (Debian)
----------------------------------------
Feature #4780: Allow $var=undef in define as parameter
http://projects.puppetlabs.com/issues/4780
Author: Nico Schottelius
Status: Needs more information
Priority: Normal
Assignee:
Category:
Target version:
Affected version:
Keywords:
Branch:
Hello!
When we encapsulate a simple type like file with a define, we would like to let
the simple type take care of errors and thus pass direct input to it. This does
not work however:
Current code:
define nginx::site($ensure=present, $source=false, $content=false) {
include nginx
$config_file="/etc/nginx/sites-enabled/$name"
file { $config_file:
owner => "root",
group => "root",
mode => 0644,
ensure => $ensure,
source => $source ? {
false => undef,
default => $source,
},
content => $content ? {
false => undef,
default => $content,
},
notify => Service['nginx'],
}
}
Expected code:
define site($ensure=present, $source=undef, $content=undef) {
include nginx
$config_file="/etc/nginx/sites-enabled/$name"
file { $config_file:
owner => "root",
group => "root",
mode => 0644,
ensure => $ensure,
source => $source,
content => $content,
notify => Service['nginx'],
}
}
If you allow specifying arguments for defined types, an optimised version would
look even smaller:
define site(__args_used=[file]) {
include nginx
$config_file="/etc/nginx/sites-enabled/$name"
file { $config_file:
owner => "root",
group => "root",
mode => 0644,
notify => Service['nginx'],
}
}
Whether the second or the third version or a complete different syntax would
fit best is one question. Clear is that the first version is code redundancy
and it should be possible to avoid it.
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-bugs?hl=en.