Ask Your Question

Editing Templates with hiera

asked 2016-04-26 09:09:21 -0600

sach gravatar image

Following mentioned is some of the portion of my .erb template,where I am able to define "LogFile" path and "LogFileSize" with hiera for per host configuration.

Option: LogFile

LogFile=<%= logfile %>

Option: LogFileSize

LogFileSize=<%= logfilesize %>

My requirement is if any of the parameter eg. LogFile or LogFileSize, if it is not applicable to some of the host,it should get commented (hashed out).

Example: on Host A,if LogFileSize is not applicable then it should be

Option: LogFile


Option: LogFileSize

#LogFileSize=<%= logfilesize %>

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-04-30 11:19:43 -0600

DarylW gravatar image

updated 2016-04-30 11:20:07 -0600

I think I've usually seen a preference to decoupling the module from hiera. in that case you would populate the value you want, either as a parameter, an array, or a config hash, and pass it to your module. That way it gives the user of your module the option to declare it directly in the call, OR pass it in via hiera. That makes it eaiser to test your code without having to put hiera in place in your fixtures for that module.

edit flag offensive delete link more

answered 2016-04-26 19:03:38 -0600

ccovarrubias gravatar image

You should be able to query hiera directly in your template:


You can setup a conditional statement dependent on the value of the result.

edit flag offensive delete link more


will that return nil if it can't find it, or is there a default value you need to specify?

DarylW gravatar imageDarylW ( 2016-04-26 20:44:27 -0600 )edit

Can you please help me with the example configuration as per the requirement posted in question section

sach gravatar imagesach ( 2016-05-03 07:20:43 -0600 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2016-04-26 09:09:21 -0600

Seen: 97 times

Last updated: Apr 30 '16