0

I am currently using Puppet with Foreman 1.17 and puppetlabs/apache version 3.1.0. All virtual hosts are defined using a .yaml file:

apache::vhost:
  vm12345_ssl:
    servername: my.example.com
    docroot: /home/my.example.com/web
    logroot: /home/my.example.com/log
    (... more configuration)

Now I would like to specify also the required Apache modules via Hiera / yaml file. But I could not find any documentation or example how to do this. One website recommends apache::mod::proxy: true; I tried this and also variants of it but could not get it to work.

What I want to accomplish: I am using the Puppet roles and profiles pattern and my webapp profile files each contain the lines below:

class profile::webapp::my_webapp_01 (
    ... some parameters
  ) {

  include profile::java
  include apache
  apache::mod { 'proxy': }
  apache::mod { 'proxy_ajp': }
  apache::mod { 'proxy_http': }
  ... more webapp-specific configuration

And my node looks like:

node 'vm12345' {
  ...
  include profile::webapp::my_webapp_01
  include profile::webapp::my_webapp_02
  include profile::webapp::my_webapp_03
}

When I include just one webapp per VM all is well, but as soon as I include several webapps in the VM I get a "Duplicate declaration" error. I think the proper way to resolve this is to use Hiera to specify the Apache modules, instead of explicitly defining them into the profile.

Please advise how to specify Apache modules via Hiera and a yaml file, or if maybe the whole approach is broken, please advise how to write the profile declarations for the Apache modules such that they can be included multiple times.

nn4l
  • 1,336
  • 5
  • 23
  • 40

2 Answers2

0

Using the roles and profiles structure:

Apache Profile:

class profile::apache {
  include ::apache
  apache::mod { 'proxy': }
  apache::mod { 'proxy_ajp': }
  apache::mod { 'proxy_http': }
}

Webapp Role:

class role::webapp::my_webapp_01 {
  include profile::java
  include profile::apache
}

Webserver Node:

node 'vm12345' {
  include role::webapp::my_webapp_01
}

You can also modify the Apache Role to take a parameter for the mods to create:

class profile::apache (
  Array $mods = [],
) {
  include ::apache
  apache::mod { $mods: }
}

It should be noted that you can also use the Apache modules' default_mods parameter, either via Puppet code or via Hiera:

Puppet

class { '::apache':
  default_mods' => ['proxy','proxy_ajp','proxy_http'],
}

Hiera

---
apache::default_mods:
  - proxy
  - proxy_ajp
  - proxy_http
Craig Watson
  • 9,575
  • 3
  • 32
  • 47
  • The OP was right with `profile::apache` & `profile::java`, etc. profile classes shouldn't include role classes. There should be one role which includes many profiles which themselves can include further profiles. What's missing here is a `role::webserver` or similar which is assigned to the node in question either manually or through an ENC. – bodgit Jul 31 '18 at 10:32
  • @bodgit thanks, at work we use the inverse terminology (we came up with the idea before it entered general use), need to mentally reset :) – Craig Watson Jul 31 '18 at 11:36
0

I am now using the code below in my profile file:

class profile::webapp::my_webapp_01 (
    ... some parameters
  ) {

  include profile::java
  include apache
  include apache::mod::proxy
  include apache::mod::proxy_ajp
  include apache::mod::proxy_http

  ... more webapp-specific configuration

This allows for multiple includes without the "Duplicate declaration" error.

However I was unable to figure out how to use Hiera / yaml files to accomplish this. Probably some extra code is required to read the parameters from a yaml file, such as hiera() and create_resource().

nn4l
  • 1,336
  • 5
  • 23
  • 40