string - Puppet conditional assignment and += operator -


in puppet, want write file string based on configuration in nodes.pp.

  • nodes.pp defines $sslclientcertconfig variable, has loadbalancerip property.
  • i want create configuration string, we'll call $config, without repeating string code. configuration string should either
    • a: if loadbalancerip valid string, combination of strings 1 , 2
    • b: if loadbalancerip empty string, string 2
  • then, using configuration string, want set variable.

i know puppet allows single declaration of variable name per scope, not know if supports += operator, or if variable declarations below work if/else clause later.

here's want try:

if $sslclientcertconfig {     $loadbalancerip = $sslclientcertconfig[loadbalancerip]      $config      if $loadbalancerip {           $config += "string1"     }     $config += "string2" }  if $config {    $custom = "true" } else {     $custom = "false" } 

is pattern supported puppet? there way can improve this?

you cannot reassign variables in puppet. instead remove empty declaration of $config , try following code

if $loadbalancerip {       $prefix = "string1" } $config = "${prefix}string2" 

example:

$prefix1 = "pref1" $config1 = "${prefix1}blabla1" $config2 = "${prefix2}blabla2" notify { $config1: } notify { $config2: } 

notice: /stage[main]/main/notify[pref1blabla1]/message: defined 'message' 'pref1blabla1' notice: /stage[main]/main/notify[blabla2]/message: defined 'message' 'blabla2'

update: aware of automatic string boolean conversion.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -