On Sep 29, 10:07 am, Carlos Sanchez <car...@carlossanchez.eu> wrote:
> Hi,
>
> In class parameters, things like x="x", y="y${x}" don't always evaluate
> right (y="yx"), seems random. I'm using 2.7.1
>
> 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/sonar
> notice: Scope(Class[Test1]): /var/sonar
> notice: Scope(Class[Test1]): /var/sonar
> notice: Scope(Class[Test1]): -----
> notice: Scope(Class[Test1]): /var/sonar/logs
> notice: Scope(Class[Test1]): /logs
> notice: Scope(Class[Test1]): /logs
>
> Note the last two messages should print "/var/sonar/logs"
> Ordering the paramenters in the order they are needed gets the same result.
>
> Just by changing the name of the parameters from class test1 to test2 I get
> different evaluations of the variables, one is right and two are wrong, you
> can see that in this gisthttps://gist.github.com/1250837
>
> Am I doing something wrong? is interpolation not supposed to work with class
> parameters?


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.

You can, however, do this:

class test1(
    $servicex = "sonar",
    $logfolderxpar = "",
    $homexpar = "") {

    $homex = ${homexpar} ? { "" => "/var/${servicex}", default => $
{homexpar} }
    $logfolderx = ${logfolderxpar} ? { "" => "${homex}/logs", default
=> ${logfolderxpar} }

    # ...
}


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to