I have about 300 apache servers that all need a common virtual host setup for our monitoring and load balancing application.
Currently, I use a wrapper class to extract the vhost information from hiera and that all works fine. What I need to do now is include a standard vhost definition that *all* servers get. I'm using hiera and YAML to achieve this but I've found myself repeating the same lines of YAML code over and over in the individual hosts' YAML files. What I'd like to do is have the standard vhost definition in the global.yaml file and an "include" of some sort in the .yaml file that references the global.yaml.
Here's what I have in global.yaml:
\# everyone gets this stuff
example::cache::servername: cache.%{::fqdn}
example::cache::docroot: '/var/www/html/example.org'
example::cache::docroot_owner: 'webmaster'
example::cache::docroot_group: 'webmaster'
example::cache::ip: '*'
Here's what I have in.yaml:
\# Wrapper class to send to apache::vhosts
profiles::webserver::vhost_wrapper::vhosts:
everyone_vhost:
cache.%{::fqdn}:
servername: %{hiera('example::cache::servername')}
docroot: %{hiera('example::cache::docroot')}
docroot_owner: %{hiera('example::cache::docroot_owner')}
docroot_group: %{hiera('example::cache::docroot_group')}
ip: %{hiera('example::cache::ip')}
So far, this works just fine but I still have to repeat all those lines in all my servers. What would be easier is if I could put the default vhost in global.yaml and reference it in.yaml file thusly:
global.yaml:
everyone_vhost:
cache.%{::fqdn}:
servername: cache.%{::fqdn}
docroot: '/var/www/html/example.org'
docroot_owner: 'webmaster'
docroot_group: 'webmaster'
ip: *
in.yaml:
profiles::webserver::vhost_wrapper::vhosts:
everyone_vhost: %{hiera('everyone_vhost')} # <-- This is where I'd like to 'reference' the global.yaml value.
Unfortunately, 'referencing' global::everyone_vhosts doesn't work in this situation. Hiera seems to convert the hash into a string so the Apache module complains. Other than using an ENC, is there a way to accomplish what I'm after? [root@ltstd001 hiera]# cat /etc/hiera.yaml
---
:backends:
- yaml
:hierarchy:
- defaults
- "%{clientcert}"
- "%{environment}"
- global
:yaml:
\# datadir is empty here, so hiera uses its defaults:
\# - /var/lib/hiera on *nix
\# - %CommonAppData%\PuppetLabs\hiera\var on Windows
\# When specifying a datadir, make sure the directory exists.
:datadir:
\#:merge_behavior: deeper
example::cache::servername: cache.%{::fqdn}
example::cache::docroot: '/var/www/html/example.org'
example::cache::docroot_owner: 'webmaster'
example::cache::docroot_group: 'webmaster'
example::cache::ip: '*'
Here's what I have in
profiles::webserver::vhost_wrapper::vhosts:
everyone_vhost:
cache.%{::fqdn}:
servername: %{hiera('example::cache::servername')}
docroot: %{hiera('example::cache::docroot')}
docroot_owner: %{hiera('example::cache::docroot_owner')}
docroot_group: %{hiera('example::cache::docroot_group')}
ip: %{hiera('example::cache::ip')}
So far, this works just fine but I still have to repeat all those lines in all my servers. What would be easier is if I could put the default vhost in global.yaml and reference it in
cache.%{::fqdn}:
servername: cache.%{::fqdn}
docroot: '/var/www/html/example.org'
docroot_owner: 'webmaster'
docroot_group: 'webmaster'
ip: *
in
everyone_vhost: %{hiera('everyone_vhost')} # <-- This is where I'd like to 'reference' the global.yaml value.
Unfortunately, 'referencing' global::everyone_vhosts doesn't work in this situation. Hiera seems to convert the hash into a string so the Apache module complains. Other than using an ENC, is there a way to accomplish what I'm after? [root@ltstd001 hiera]# cat /etc/hiera.yaml
---
:backends:
- yaml
:hierarchy:
- defaults
- "%{clientcert}"
- "%{environment}"
- global
:yaml:
\# datadir is empty here, so hiera uses its defaults:
\# - /var/lib/hiera on *nix
\# - %CommonAppData%\PuppetLabs\hiera\var on Windows
\# When specifying a datadir, make sure the directory exists.
:datadir:
\#:merge_behavior: deeper