Ask Your Question

Where can I put files/templates where hiera can reference them?

asked 2017-07-16 14:27:23 -0600

wfsaxton gravatar image

(Sorry, I accidentally accepted the answer to my last question and it wasn't correct)

Let's say I have a module "mymodule" which use a template to create /etc/mymodule.conf. I would like the user to be able to define this template themselves. Let's say my user wants a different template file the "Linux" and "SunOS" OS families. "mymodule" exposes the class parameter "$template" which is just a path to the template to use.

I'm defining all my classes via hiera, so my site.pp is


Now, in hiera I have the following:


  - mymodule

mymodule::template: 'profile/mymodule/mymodule.conf-Linux.epp


mymodule::template: 'profile/mymodule/mymodule.conf-SunOS.epp

This works fine. But the only reason it works is because I'm using a fake class called "profile" in my module path to store all of my files and templates:


This seems like a hack. Is there a better way to reference or store templates like this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-07-17 01:21:31 -0600

negast gravatar image

So you want to store the templates in the modules then? If so define your templates following

file { 'filename': ensure => file, content => template($::hieravariable), }

in hiera myclas::hieravariable: '<module_name>/<template name="">' so it will load -> modulename/templates/tempaltename

edit flag offensive delete link more


I don't know/care where to store it. I'm just looking for the best place to do so. I know how to store templates within modules but I don't want a user to have to mess with the module. I just want him to use his own storage mechanism.

wfsaxton gravatar imagewfsaxton ( 2017-07-17 07:31:34 -0600 )edit

so you want to make the source of templates work more like the content parmaeter? Where the source can be from anywhere more options but you still want it to act like a template base on the users facts etc, ? I'm sorry for asking this many questions, i'm just trying to understand what you want

negast gravatar imagenegast ( 2017-07-17 07:44:05 -0600 )edit

Yes, its more like content where the module itself doesn't know the contents. Kind of like MOTD where it can be free-form anything. I was wondering if there was a "best practice" for a file/template repository location.

wfsaxton gravatar imagewfsaxton ( 2017-07-17 07:48:43 -0600 )edit

I understand that the best place for a module-specific file or template is within the module, and you expose the variables within the template as, say, class parameters...but just wondering if there is more of a free-form area.

wfsaxton gravatar imagewfsaxton ( 2017-07-17 07:52:11 -0600 )edit

Perhaps the best thing to do is to just put the content itself inside of a hiera variable.

wfsaxton gravatar imagewfsaxton ( 2017-07-17 07:53:09 -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

1 follower


Asked: 2017-07-16 14:27:23 -0600

Seen: 239 times

Last updated: Jul 17 '17