Introducing Hiera!
Hiera allows us to define data structures that can then be accessed in a class and passed to a template.
This PR shows how it can be used to pass in different URLs for apache rewrites dependant on the environments domain.
Hiera's main config lives in /etc/puppet/hiera.yaml
---
:backends:
- yaml
:yaml:
:datadir: '/etc/puppet/hieradata'
:hierarchy:
- "%{domain}/supporter_url_redirects"
- common
"%{domain}/supporter_url_redirects" references /etc/puppet/hieradata/edheroy.com/supporter_url_redirects.yaml
common references /etc/puppet/hieradata/common.yaml
/etc/puppet/hieradata/edheroy.com/supporter_url_redirects.yaml looks like this
---
au:
url: 'http://core-au.edheroy.com'
gb:
url: 'http://core-gb.edheroy.com'
nz:
url: 'http://core-nz.edheroy.com'
us:
url: 'http://core-us.edheroy.com'
So in the webapp-vhost.pp we can do this:
$gb_redirect = hiera('gb')
Then in the template we can access it like this:
<%= @gb_redirect['url'] %>