class test1($servicex = "sonar",$logfoldera = "${homex}/logs",$logfoldere = "${homey}/logs",$logfolderh = "${homez}/logs",$logfolder = "${homex}/logs",$homex = "/var/${servicex}",$homey = "/var/${servicex}",$homez = "/var/${servicex}") {notice($homex)notice($homey)notice($homez)notice("-----")notice($logfoldera)notice($logfoldere)notice($logfolderh)}
output :notice: Scope(Class[Test1]): /var/sonarnotice: Scope(Class[Test1]): /var/sonarnotice: Scope(Class[Test1]): /var/sonarnotice: Scope(Class[Test1]): -----notice: Scope(Class[Test1]): /var/sonar/logsnotice: Scope(Class[Test1]): /logsnotice: Scope(Class[Test1]): /logs
This seems to be a bug as things be weirder the more I test.
class test1(
$servicex = 'servicex',
$servicey = 'servicey',
$service1 = "/bar/${servicex}",
$service2 = "/bar/${servicey}",
$homex = 'homex',
$home1 = "/bar/${homex}"
) {
notice($service1)
notice("-----")
notice($service2)
notice("-----")
notice($home1)
}
include test1
Gets the output of:
notice: Scope(Class[Test1]): /bar/servicex
notice: Scope(Class[Test1]): -----
notice: Scope(Class[Test1]): /bar/servicey
notice: Scope(Class[Test1]): -----
notice: Scope(Class[Test1]): /bar/
If you add underscores in the variable names like so:
class test1(
$service_x = 'servicex',
$service_y = 'servicey',
$service1 = "/bar/${service_x}",
$service2 = "/bar/${service_y}",
$homex = 'homex',
$home1 = "/bar/${homex}"
) {
notice($service1)
notice("-----")
notice($service2)
notice("-----")
notice($home1)
}
include test1
You get this response:
notice: Scope(Class[Test1]): /bar/
notice: Scope(Class[Test1]): -----
notice: Scope(Class[Test1]): /bar/
notice: Scope(Class[Test1]): -----
notice: Scope(Class[Test1]): /bar/
This is most obviously a scoping issue and the fact that service is being treated special makes me think a magic service variable is being set someplace internally.
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ubA3F3GClqcJ.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
I do think there's a bug, but I'm not confident it's the one you think
it is. I find no documentation of any difference in variable
interpolation in class parameter defaults than in any other context,
so I expect the interpolation to be performed according to the same
rules as elsewhere. Specifically, I expect interpolation to draw on
only variables available in the scope in which the host string
appears. A class's parameters cannot be in scope in that class's own
parameter list definition, because their values are not known at that
point. Therefore, you should not be able to interpolate one
parameter's actual value into the default value of a another
parameter. That is, NONE of the interpolations in your example should
work.
[...]class openssh (
$service = $openssh::params::service,$service_status = $openssh::params::service_status,$process = $openssh::params::process,$process_args = $openssh::params::process_args,$config_dir = $openssh::params::config_dir,$config_file = $openssh::params::config_file,$config_file_mode = $openssh::params::config_file_mode,$config_file_owner = $openssh::params::config_file_owner,$config_file_group = $openssh::params::config_file_group,$config_file_init = $openssh::params::config_file_init,$pid_file = $openssh::params::pid_file,$data_dir = $openssh::params::data_dir,$log_dir = $openssh::params::log_dir,$log_file = $openssh::params::log_file) inherits openssh::params {