On Tuesday, March 12, 2013 10:53:46 AM UTC-5, phundisk wrote:
>
> I have a define which 
>
> define testing1::instance (
>    $hostSuffix = "-$environment", 
>    $testingDb = "db1$hostSuffix$dnsDomainInt",
> )
>
> In my nodes.pp I explicitly set the $environment variable.  However when I 
> use the property 'testingDb' in a template, it comes out as only 'db1'  Is 
> there something I am doing wrong in this define?
>


Yes.  The default values for a definition's (or class's) parameters cannot 
safely draw on the values of other parameters of the same object.  It is 
therefore incorrect for the default value of the $testingDb parameter to 
use the $hostSuffix parameter.  I would write that definition something 
like this, instead:

define testing1::instance (
  $hostSuffix = 'NOTSET',
  $testingDb = 'NOTSET'
) {

  $realHostSuffix = $hostSuffix ? {
    'NOTSET' => "-${environment}",
    default => $hostSuffix
  }

  $realTestingDb = $testingDb ? {
    'NOTSET' => "db1${realHostSuffix}${dnsDomainInt}",
    default => $testingDb
  }

  # ... use $realHostSuffix and $realTestingDb ...
}


John

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


Reply via email to