1

Queston: Using the roles & profiles method, is it possible to use 'puppetlabs-apache', '8.3.0' with a hiera lookup?

Context:

  • I am using mod 'puppetlabs-apache', '8.3.0' to configure an apache server. I have a large number of apache re-write rules for various sites.

  • Each site is configured hiera, e.g hiera.yaml:

     paths:
        - site/%{::site}.yaml
        - role/%{::role}.yaml
    
  • where a webapp.pp role installs & configures apache

  • it would be nice to lookup apache config in a site-dependent fashion, but can't find any documentation that helps


Notes

  • I have found a similar question here, but don't think that covers my particular use-case
  • If hiera is unavailable for this module I could perform some logic in webapp.pp, e.g. something like this: If ($facts['site'] == 'SITE-A') {outline rewrites for SITE-A}
  • however, this approach feels rather messy
0

1 Answer 1

0

Ok so just in case anyone benefits, the solution was really straightforward and shows my puppet noob status.

Solution:

Looking at the docs you'll see the majority of data types are arrays, take the following example:

  apache::vhost { 'aliases.example.com':
      serveraliases => [
        'aliases.example.org',
        'aliases.example.net',
      ],
      port          => 80,
      docroot       => '/var/www/aliases',
    }

here serveraliases is an array. So you can simply lookup an array through hiera:

        class profiles::apache::secure_vhost(
            # Hiera lookup
            Array $site_serveraliases    = lookup('apache_site_serveraliases') )
            {
            apache::vhost { 'aliases.example.com':
            serveraliases => $site_serveraliases,
            port          => 80,
            docroot       => '/var/www/aliases',
            }
           )

Where $apache_site_serveraliases is a yaml array that varies between sites, e.g.:

apache_site_serveraliases:
  - paris.site.name
  - london.site.name
  - nyc.site.name

This way you can lookup apache_site_serveraliases in a site-dependent fashion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .