[Puppet Users] Hiera hashes and arrays in ERB templates

2013-01-04 Thread Andy Taylor
Hi,

I'm trying to build a module for haproxy which fetches all the 
configuration data from Hiera to populate the haproxy config file. I've run 
into a number of issues though when I try to use hashes. Ideally, I want to 
use something like this:

haproxy_listeners :
 cluster1 :
  ip : '192.168.0.2'
  port : '80'
  servers : 
   server1 :
ip : '192.168.0.3'
port : '8080'

So a hash of clusters with each cluster containing a nested hash of 
servers. Is this possible with Hiera/ERB? It's easy enough to iterate over 
the first hash, but I can't work out how to extract the contents of the 
nested hash. Or I might just be approaching this in entirely the wrong 
way... Any help would be much appreciated.

Thanks,

Andy

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/vtr8gCCwuBsJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



Re: [Puppet Users] Hiera hashes and arrays in ERB templates

2013-01-04 Thread Wolf Noble
not sure if this is the best way to do this, but, taking from a different 
module I have:


hiera yaml:

snmp_filesystems:
  root: {
mountpoint:  '/',
threshold:   '10%'
  }
snmp_collector:
  test: {
ip:'1.2.3.4',
group: 'readonly',
community: 'somecommunity'
  }

class:

class snmp::params(
filesystems = hiera(snmp_filesystems, undef),
collector = hiera(snmp_collector, undef)
{
#…
}

template:

%
  collector = scope.lookupvar('snmp::params::collector')
  filesystems = scope.lookupvar('snmp::params::filesystems')
-%

% collector.each_pair do |key, hash| -%
group  %=hash['group']-%  v2c  %=key%
%end-%

# Filesystem monitoring enabled
% filesystems.each_pair do |key, hash| -%
# %=key%
disk %=hash['mountpoint']-%  %=hash['threshold']%
%end-%




does that help at all?


Wolf Noble
UNIX Team Lead
Datapipe Managed IT Services
1.201.792.4847 (international) x2910
1.888.749.5821 (toll free) x2910




On Jan 4, 2013, at 9:37 AM, llowder llowde...@gmail.com wrote:



 On Friday, January 4, 2013 9:11:28 AM UTC-6, Andy Taylor wrote:
 Hi,

 I'm trying to build a module for haproxy which fetches all the configuration 
 data from Hiera to populate the haproxy config file. I've run into a number 
 of issues though when I try to use hashes. Ideally, I want to use something 
 like this:

 haproxy_listeners :
  cluster1 :
   ip : '192.168.0.2'
   port : '80'
   servers :
server1 :
 ip : '192.168.0.3'
 port : '8080'

 So a hash of clusters with each cluster containing a nested hash of servers. 
 Is this possible with Hiera/ERB? It's easy enough to iterate over the first 
 hash, but I can't work out how to extract the contents of the nested hash. Or 
 I might just be approaching this in entirely the wrong way... Any help would 
 be much appreciated.


 I haven't used the function myself, but this looks like it would be a good 
 case for a define + create_resources(), which I think is part of stdlib. You 
 might need to restructure the hashes slightly, but I think that will be the 
 best approach.


 Thanks,

 Andy

 --
 You received this message because you are subscribed to the Google Groups 
 Puppet Users group.
 To view this discussion on the web visit 
 https://groups.google.com/d/msg/puppet-users/-/DPkuzR8Q8soJ.
 To post to this group, send email to puppet-users@googlegroups.com.
 To unsubscribe from this group, send email to 
 puppet-users+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/puppet-users?hl=en.




This message may contain confidential or privileged information. If you are not 
the intended recipient, please advise us immediately and delete this message. 
See http://www.datapipe.com/legal/email_disclaimer/ for further information on 
confidentiality and the risks of non-secure electronic communication. If you 
cannot access these links, please notify us by reply message and we will send 
the contents to you.

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.