puppet propagate variable from node to erb tamplate?

Posted by picca on Server Fault See other posts from Server Fault or by picca
Published on 2011-01-10T16:13:47Z Indexed on 2011/01/10 16:55 UTC
Read the original article Hit count: 238

Filed under:

Is it possible to declare variable in node and than propage it way down to the erb template?

Example:

node basenode {
  $myvar = "bar" # default
  include myclass
}

node mynode extends basenode {
  $myvar = "foo"
}

class myclass {
  file { "/root/myfile":
    content => template("myclass/mytemplate.erb")
    ensure  => present,
  }
}

Source of mytemplate.erb:

myvar has value: <%= myvar %>

I know that my example might be complicated. But I'm trying to propagate file on (almost) all my nodes and I want its content to be altered depending on the node which requests the file. The $myvar = "bar" statement should be default when node does not override its value.

Is there a solution to my problem? I'm using puppet 0.24.5

© Server Fault or respective owner

Related posts about puppet