Ask Your Question
1

How to configure Hiera defaults?

asked 2014-07-29 07:34:22 -0500

nn4l gravatar image

updated 2014-07-30 06:26:45 -0500

I have a lot of almost identical apache2 configurations and I would like to split the Hiera configuration into a common part and a website specific part.

Here's my current configuration (the apache class is the one from puppetlabs):

/etc/puppet/manifests/site.pp:

node 'website0181.mydomain.de' {

    apache::mod { 'include': }
    apache::mod { 'negotiation': }
    apache::mod { 'proxy_ajp': }

    class { 'apache':
            default_mods    => false,
            error_documents => true,
            serveradmin     => 'admin@mydomain.de',
    }

    $myvhosts = hiera('apache::vhosts', {})
    create_resources('apache::vhost', $myvhosts)
}

/etc/puppet/hieradata/node/website0181.mydomain.de.yaml:

apache::vhosts:
   "%{::fqdn}":
    docroot: /home/web0000/www
    logroot: /home/web0000/log
    port: 80
    redirect_status: permanent
    redirect_dest: https://%{::fqdn}
    serveraliases: "%{::fqdn}"
    servername: "%{::fqdn}"
   "%{::fqdn}_ssl":
    docroot: /home/web0000/www
    logroot: /home/web0000/log
    port: 443
    servername: "%{::fqdn}"
    ssl: true
    proxy_pass:
      - { path: /site_specific_path, url: 'ajp://127.0.0.1:9012/site_specific_path' }

... (more options)

The other yaml files look the same, the only difference is the "{ path: /sitespecificpath, url: 'ajp://127.0.0.1:9012/sitespecificpath' }" line.

I would like to move all common options into /etc/puppet/hieradata/common.yaml and leave only the site specific line in website0181.mydomain.de.yaml:

apache::vhosts:
   "%{::fqdn}_ssl":
    proxy_pass:
      - { path: /site_specific_path, url: 'ajp://127.0.0.1:9012/site_specific_path' }

But this does not work. The configuration is only retrieved from common.yaml if the apache::vhosts tag is not available in website0181.mydomain.de.yaml. However I need to merge or concat both configurations somehow.

Please advise how to properly use a default configuration for this case.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-07-29 17:41:56 -0500

ramindk gravatar image

updated 2014-07-30 12:44:16 -0500

You probably want to look into the role/profiles paradigm. Some decent data here.

node def:

node 'website\d+.mydomain.de' {
  include profile::apache
}

wrapper class

class profile::apache {
  apache::mod { 'include': }
  apache::mod { 'negotiation': }
  apache::mod { 'proxy_ajp': }

  class { 'apache':
    default_mods    => false,
    error_documents => true,
    serveradmin     => 'admin@mydomain.de',
  }

  # Note the change to hiera_hash here. This will merge keys as well as include vhosts 
  # from any matching part of the hierarchy
  $myvhosts = hiera_hash('apache::vhosts', {})
  create_resources('apache::vhost', $myvhosts)
}

hieradata/some_role.yaml

---
   "%{::fqdn}_ssl":
    proxy_pass:
      - { path: /site_specific_path, url: 'ajp://127.0.0.1:9012/site_specific_path' }

hieradata/specific_server.yaml

---
   "%{::fqdn}_ssl":
    docroot: /home/web0000/www
    logroot: /home/web0000/log
    port: 443
    servername: "%{::fqdn}"
    ssl: true

Then just set the hiera data per server in yaml files. You could also set a new fact like $role that might set common data per set of machines. The example I linked to does it that way.

edit flag offensive delete link more

Comments

thanks , I actually want to simplify the Hiera data, not the puppet class. I have clarified the question to reflect this better.

nn4l gravatar imagenn4l ( 2014-07-30 06:29:27 -0500 )edit

Updated. Changed hiera to hiera_hash since you want to merge keys. BTW that was buried in the link I mention in the first line. You really should read it if you haven't.

ramindk gravatar imageramindk ( 2014-07-30 12:45:33 -0500 )edit

maybe it helps - you can also set defaults as a third parameter in the create_resources function, if you don't want to declare them in hiera: http://docs.puppetlabs.com/references/latest/function.html#createresources

khaefeli gravatar imagekhaefeli ( 2014-08-04 07:46:24 -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: 2014-07-29 07:34:22 -0500

Seen: 1,401 times

Last updated: Jul 30 '14