Ask Your Question
-1

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

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

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

hiera_include('classes')

Now, in hiera I have the following:

Linux.pp:

classes: 
  - mymodule

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

Solaris.pp:

classes:
  -mymodule
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:

<module-path>/profile/templates/mymodule/

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
0

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

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

Comments

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

1 follower

Stats

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

Seen: 60 times

Last updated: Jul 17