ERB template does not collect variables from hieradata
I have a puppet infrastructure and I created a new module that references the variables that exist in the hamadata yaml files that everything works fine in the manifest section. However, when I access them in the erb template, the variables do not display anything after the puppet rus. There is a file, just variables ..
init.pp
class cms_nxlog ($msi_file) {
anchor { 'cms_nxlog::begin': }
->
file { "C:/CMS/${cms_nxlog::msi_file}":
ensure => 'file',
source => "puppet:///modules/cms_nxlog/${cms_nxlog::msi_file}",
owner => 'Administrators',
group => 'Users',
mode => '0770'
}
->
package { 'NXLOG-CE':
ensure => installed ,
source => "C:\\CMS\\${cms_nxlog::msi_file}",
}
->
file { "C:/Program Files (x86)/nxlog/conf/nxlog.conf":
ensure => 'file',
content => template('cms_nxlog/nxlog.conf.erb'),
owner => 'Administrators',
group => 'Users',
mode => '0770',
notify => Service['nxlog'],
}
->
service { 'nxlog' :
ensure => 'running',
require => Package['NXLOG-CE']
}
->
anchor { 'cms_nxlog::end': }
}
Relevant section of the erb template:
<Output out>
Module om_udp
Host <%= scope.lookupvar('cms::log_server') %>
Port <%= scope.lookupvar('cms_nxlog::port') %>
</Output>
Relevant yaml sections
cms_nxlog::msi_file: nxlog-ce-2.8.1248.msi
cms_nxlog::port: 514
cms::log_server: 192.168.1.50
This all fits perfectly, just copying the erb doesn't seem to populate the contents of the scope.lookupvar, so I end up saying
<Output out>
Module om_udp
Host
Port
</Output>
As I said, the variables seem to work fine in the manifest and not in the template. I compared this to a similar module that seems to work to no avail.
thank
source to share
You need to call scope.function_hiera
, not scope.lookupvar
:
<Output out>
Moudule om_udp
Host <%= scope.function_hiera(['cms::log_server']) %>
Port <%= scope.function_hiera(['cms_nxlog::port']) %>
</Output>
Note that it function_hiera
takes as an argument array
, not string
.
Hope this helps!
source to share