Ask Your Question

composition nodes of the parts of the module

asked 2014-12-30 03:36:50 -0600

fura gravatar image

hi there

I want to describe the module in the node "solve" any part of this module will "work":

class myclass {
   service {...}
   file {... content => template (blabla.erb), ...}
   package {...}

class myclass :: feature1 {
   $ myVar = ['add this line', 'and second']

class myclass :: feature2 {
   $ myVar = ['this feature enabled']

#FeatureX these can be any number, and it would be good to them then it was easy to add

A description of the host may include different parts of the module

node "mynode" {
   include myclass :: feature1
   include myclass :: feature2
   include myclass

blabla.erb looks like this:

    <% if myVar%> <% @ myVar.each do | var | -%> <% = var%>
    <% end -%> <% end%>

this does not work, because the variable myVar described in myclass :: feature is local and is not visible in the generation templat'a =( ... if i definition var in node i loose encapsulation

please tell me how to do it?

thank you

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-12-30 23:17:03 -0600

cbarbour gravatar image

updated 2014-12-30 23:17:35 -0600

Direct answer to your question:

In blabla.erb, you can use the scope.lookupvar() function call or scope[] array to check to see if $::myclass::feature1::myvar and $::myclass::feature2::myvar are defined, and if so take an action based on that information. See:

With this approach, you need to make sure that myclass::feature1 and myclass::feature2 are included into your catalog before ::myclass so that those variables are defined when blabla.erb is rendered.

Indirect answer to your question:

The approach you are using isn't very clean, and is going to be extremely difficult to maintain in the long run. I'd recommend instead that you use puppetlabs/concat to build the file from fragments.

With the fragment approach, you can define a header and tail that will always be included. ::myclass::feature1 and ::myclass::feature2 can insert their own file fragments on the condition they have been included in the catalog. This approach is much more standard and flexible.

Ideally, whatever ::myclass manages supports config.d style config directories, and concat isn't needed at all.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-12-30 03:36:50 -0600

Seen: 54 times

Last updated: Dec 30 '14