Ask Your Question

setting a function as value via hiera

asked 2016-02-24 09:47:17 -0500

rautha gravatar image


I'm currently using the puppet/apache module to manage apache. I have lot's of servers with large blocks of rewrite rules, but those rewrite rules are most times the same, so I want to save them to a seperate file, read that file and add it as a custom fragment to the apache configuration. This works like a charm with puppet code.

apache::vhost { '':
        port    => '80',
        docroot => '/var/www',
        custom_fragment => file('role/apache/rules.conf'),

but I want to give all virtualhost configuration to hiera and use create_resources to build the vhost configurations. Like this:

        port: '80'
        docroot: '/var/www'
        custom_fragment: file('role/apache/rules.conf')

this is adding only the text "file('role/apache/rules.conf') to the apache configuration it is not executing the function.

Is there any way to achieve this.

Thank you in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-03-04 21:08:51 -0500

DarylW gravatar image

I think you would have to create a define that can take all of the parameters, and fill them in as you would expect, and populate that with data from hiera/create_resources.. something similar to this

create_resources(custom_vhost, $custom_vhosts)
define custom_vhost(
  $port = '80', 
  $docroot = '/var/www',
) {
    apache::vhost { $name:
          port    => $port,
          docroot => $docroot,
          custom_fragment => file($fragment_file),

If you need to conditionally set custom_fragment to undef, or do something else, it could be changed to accommodate.

edit flag offensive delete link more

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: 2016-02-24 09:47:17 -0500

Seen: 151 times

Last updated: Mar 04 '16