Lookup another node's hiera data - fqdn hierarchy

937 views
Skip to first unread message

treydock

unread,
Jul 20, 2012, 2:13:18 PM7/20/12
to puppet...@googlegroups.com
I've begun using Hiera in combination with Foreman, primarily storing data that is best left in Array/Hash form.  I'd like to be able to have a module, in this case BackupPC, query all the Hiera data for each node where the backup directories/databases are stored.  Then use all that information on the BackupPC server to generate proper configuration files for each node's backups.  Here's what I have so far...

$ cat /etc/puppet/hiera.yaml 
---
:hierarchy:
  - %{fqdn}
  - common
:backends:
  - yaml
  - puppet
:yaml:
  :datadir: '/etc/puppet/hieradata'
:puppet:
  :datasource: data


An example of the BackupPC information in hiera
$ cat /etc/puppet/hieradata/dc-ctrl.tamu.edu.yaml 
---
backuppc_db_dumps:
  foreman:
    backup_dir: '/usr/share/foreman'
  mysql:
    backup_dir: '/etc'

I am currently using that data to create dump scripts on each node, and would like to re-use the same information to automatically configure the backup server to grab those locations.

This attempt may work, but it doesn't 'feel' right to me by overriding the fqdn fact.

/etc/puppet/modules/test  $ cat manifests/hiera_lookup.pp 
class test::hiera_lookup {
  $nodes = foreman('fact_values', 'fact = fqdn')

  if $nodes {
    create_resources('test::hiera_lookup::get_data', $nodes)
  }
}

define test::hiera_lookup::get_data (
  $fqdn
) {

 $data = hiera("backuppc_db_dumps", false)

  if $data { notify { $data: } }

}

Is there a better approach to override scope and grab what data from hiera that would normally not be available to a node?

Thanks
- Trey

Garrett Honeycutt

unread,
Jul 21, 2012, 10:57:13 PM7/21/12
to puppet...@googlegroups.com
This would be a great place to use exported resources[1]. Each node
could still use Hiera to determine if they should be backed up (or what
should be backed up) and export a resource and the backup server could
collect.

[1] - http://docs.puppetlabs.com/guides/exported_resources.html

-g

--
Garrett Honeycutt

206.414.8658
http://puppetlabs.com

treydock

unread,
Jul 23, 2012, 3:21:10 PM7/23/12
to puppet...@googlegroups.com
Looking at some of online documentation I see no means to either export the hash variable pulled into the modules from hiera or to export the defines called with "create_resources".

Is there a way to do something like @@$backuppc_db_dumps = hiera('backuppc_db_dumps') ?  Or possibly a way to export a custom define with all the parameters passed to it?

Thanks
- Trey 
Reply all
Reply to author
Forward
0 new messages