Skip to content

Instantly share code, notes, and snippets.

@20after4
Forked from beddari/gist:2197910
Created October 28, 2012 15:06
Show Gist options
  • Save 20after4/3968845 to your computer and use it in GitHub Desktop.
Save 20after4/3968845 to your computer and use it in GitHub Desktop.
hiera example
---
:hierarchy:
- %{env}/%{variant}_%{role}_%{group}_%{location}
- %{env}/%{variant}_%{role}_%{group}
- %{env}/%{variant}_%{role}
- %{env}/%{variant}
- %{env}
:backends:
- yaml
:yaml:
:datadir: '/etc/puppet/hieradata'
node x {
# No params here, to be able to easily work with ENCs
include server_variant
}
class server_variant {
# This class is our source of truth!
# The first yaml-file that would be searched with these params would be
# hieradata/dev/rhel6_pg_external_vagrant.yaml
class { 'server_base':
variant => 'rhel6',
env => 'dev',
group => 'external',
role => 'pg',
location => 'vagrant'
}
}
class server_base (
$variant = 'rhel6',
$env = 'prod',
$role = 'unset',
$group = 'unset',
$location = 'unset'
) inherits server_base::params {
# Veryfing that class params are valid with validate_re from stdlib
validate_re($variant, hiera('server_variants'))
validate_re($env, hiera('server_envs'))
validate_re($role, hiera('server_roles'))
validate_re($group, hiera('server_groups'))
validate_re($location, hiera('server_locations'))
# Do example stuff with string values
class { 'puppet_client':
puppetmaster => hiera('puppet_client_puppetmaster'),
masterport => hiera('puppet_client_masterport'),
pluginsync => hiera('puppet_client_pluginsync'),
daemon => hiera('puppet_client_daemon'),
report => hiera('puppet_client_report'),
usecacheonfailure => hiera('puppet_client_usecacheonfailure'),
maxmempct => hiera('puppet_client_maxmempct'),
keepalive => hiera('puppet_client_keepalive')
}
# Do example stuff with hashes and create_resources
class { 'yum':
# Settings go here if you need them
}
# Lookup a hash of repos and create them
$yum_sources = hiera_hash('yum_sources')
create_resources ('yum::source', $yum_sources)
# Lookup all package resources and act on them
$server_packages = hiera_hash('server_packages')
create_resources ('package', $server_packages)
# Also install packages from a ENC-provided global var?
if is_array($::node_packages) {
package { $::node_packages:
ensure => installed
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment