On Thursday, October 8, 2015 at 9:52:29 AM UTC-5, Sergiu Cornea wrote:
 

> So therefore, what I am trying to do, is that I've got a template which 
> does this for me, and I have specified A CLASS instead of define as you've 
> said I was getting an error saying that the couldn't associate alias 
> because file it is already declared (because of its path). So, the class 
> i've created makes a file from an erb template. However, when I am running 
> Puppet I just get printed in the file the name of the class instead of the 
> data.
>
>

It appears, then, that the problem is centered around your template.  If 
you have not already done so, you should read the templating docs 
<http://docs.puppetlabs.com/puppet/latest/reference/lang_template.html>.

If you are asking specifically about the resulting of outputting the value 
of variable 'title', then yes, it will evaluate to the name of the class or 
title of the defined type from which the template is called.  Although 
using that might make sense if you're calling from a defined type, it is 
unlikely to make sense if you call from a class.  In the latter case, 
you'll need to provide the data you want to plug in there via a different 
variable.  If you want to output multiple rules, then perhaps you need an 
array or hash describing them and their per-rule data.  It looks like the 
hash obtained via hiera('omd_rules') (against the data presented in your 
pastebin snippet) might be exactly what you need there.

If you rename the hiera key to 'omd::omd_rules::rules' then maybe something 
along these lines might work:

modules/omd/manifests/omd_rules.pp:

class omd::omd_rules ($rules) { 
  file { '/omd/sites/test/etc/check_mk/multisite.d/wato/bi.mk':
    ensure  => 'file', 
    content => template('omd/bi.mk.erb'), 
  } 
}


modules/omd/templates/bi.mk.erb:

<% @rules.each { |rule, props| -%>
aggregation_rules["<%= rule %>"] = {
 'aggregation': 'worst!1!2',
 'comment': u'All the services associated with the customer',
 'nodes': [<%=
    props['omd_ip'].zip(props['omd_service']).map { |ip, service|
      "(u'#{ip}', u'#{service}')"
    }.join(",\n")
 %>],
 'params': [],
 'title': u'<%= rule %> Services'
}
<% } -%>

 

> I was thinking about using concat but I am a Puppet beginner and I am not 
> really sure how to go about incorporating the erb logic in the concat 
> function.
>
>

I don't think you need Concat, and in my view, Concat is one of those 
things best reserved for when you really need it.  If you did want to use 
it, though, then you would incorporate ERB by using the template() function 
to define the contents of one or more fragments.  The beauty of Concat is 
that you can define different pieces of the target file in different 
places; this allows a cooperative approach to defining the content that 
does not depend on all the pieces being known or even numbered in advance.

Note also, however, that if you simply have a fixed number of known pieces 
from which you want to construct your overall content, then you can either 
physically combine them into one template, or you can make separate 
templates and list each one among the arguments to the same template() 
call.  This is better than Concat if it is applicable.


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 view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/84687a02-db64-46c8-a8e7-f9f91e420a7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to