Ask Your Question
0

Editing Templates with hiera

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

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

LogFile=/tmp/test.log

Option: LogFileSize

#LogFileSize=<%= logfilesize %>

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

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

DarylW gravatar image

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

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
0

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

ccovarrubias gravatar image

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

scope.function_hiera(['module::var'])

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

edit flag offensive delete link more

Comments

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 -0500 )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 -0500 )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

2 followers

Stats

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

Seen: 65 times

Last updated: Apr 30 '16