Score:1

How to use puppet-apache mod (v8.3.0) with hiera?

cw flag

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
Score:0
cw flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.