hiera specifying content as template?

166 views
Skip to first unread message

Jakov Sosic

unread,
May 23, 2014, 10:03:03 PM5/23/14
to puppet...@googlegroups.com
I'm looking at this code:


define logstash::configfile(
$content = undef,
$source = undef,
$order = 10
) {

file_fragment { $name:
tag => "LS_CONFIG_${::fqdn}",
content => $content,
source => $source,
order => $order,
before => [ File_concat['ls-config'] ]
}
}


Now, I'm doing a create_resource on that one:

$logstash_configs = hiera_hash('logstash::configfiles', {})
create_resources(::Logstash::Configfile, $logstash_configs)


Problem is I cannot force a content to be an erb template....

Whatever I write in hiera, it is interpreted as text, for example:


logstash::configfiles:
'input_apache':
content: "template('adriatic/logstash/input_apache.erb')"
order: '10'


Just writes text:
template('adriatic/logstash/input_apache.erb')

into logstash config file, while I expect it to parse a template.

What am I doing wrong? Is there a way to force Hiera to pass the value
as a code and not as clear text?

Thank you

Spencer Krum

unread,
May 24, 2014, 7:17:54 PM5/24/14
to puppet...@googlegroups.com

Hiera isn't running the function for you. No worries. You can change it like this:


logstash::configfiles:
  'input_apache':
    content: 'adriatic/logstash/input_apache.erb'

    order:   '10'


define logstash::configfile(
  $content = undef,
  $source = undef,
  $order = 10
) {

  file_fragment { $name:
    tag     => "LS_CONFIG_${::fqdn}",

    content => template($content),


    source  => $source,
    order   => $order,
    before  => [ File_concat['ls-config'] ]
  }
}


What you're doing with specifying both a source and a content... I'm not sure what you're going for there. Generally you use just one. Calling template on an undefined string might cause you issues, so you might have to add some error checking. I would recommend removing the source functionality from this defined type.


Thanks,

Spencer


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/537FC58C.2070507%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages