Skip to content

Instantly share code, notes, and snippets.

@kimor79
Last active August 29, 2015 14:06
Show Gist options
  • Save kimor79/b0cdd99cb98c01892049 to your computer and use it in GitHub Desktop.
Save kimor79/b0cdd99cb98c01892049 to your computer and use it in GitHub Desktop.
Cross-module variables and hiera
I'm using puppet 3 with roles (mostly), profiles, and hiera. In one module
(profiles::collectd) I use hiera_array to get the values for pdxcat/collectd's
module's tcpconns_localports variable. When I define all of the values I want
in hiera, everything is fine. However, I would like to also define values in a
profile's class rather than having to define it in every role's yaml file that
includes said profile. I haven't been able to get that to work yet.
---
:hierarchy:
- nodes/%{::fqdn}
- sites-roles/%{::site}/%{::role}
- roles/%{::role}
- sites/%{::site}
- operatingsystemrelease/%{::operatingsystemrelease}
- operatingsystemmajrelease/%{::operatingsystemmajrelease}
- operatingsystem/%{::operatingsystem}
- osfamily/%{::osfamily}
- virtualization/%{::virtual}
- common
---
classes:
- profiles::collectd
profiles::collectd::tcpconns_localports:
- 22
profiles::collectd::tcpconns_remoteports:
- 22
- 25
- 80
- 443
- 3306
- 5432
- 8140
- 8192
- 61613
---
classes:
- profiles::postgresql::server
- profiles::postgresql::client
postgresql::globals::version: '9.3'
postgresql::server::listen_addresses: '*'
# Adding this here works as expected:
#profiles::collectd::tcpconns_localports:
# - 5432
class profiles::postgresql::server {
class { '::postgresql::server': }
# I would like to be able to add this here so I don't have to remember to
# add it to every %{::role}.yaml which includes this class.
#$::profiles::collectd::tcpconns_localports += [ '5432' ]
}
class profiles::collectd {
# This is an array lookup so multiple hiera files can add ports to watch.
$tcpconns_localports = hiera_array('profiles::collectd::tcpconns_localports')
$tcpconns_remoteports = hiera_array('profiles::collectd::tcpconns_remoteports')
# NOTE: If you need to pass "false" onto the collectd config make sure to
# quote the false (foo => 'false') as some templates only do a simple if
# statement (if @foo) which when foo is undef evaluates to false.
class { '::collectd':
purge => true,
purge_config => true,
recurse => true,
}
class { '::collectd::plugin::tcpconns':
listening => 'false',
localports => $tcpconns_localports,
remoteports => $tcpconns_remoteports,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment