On Monday, August 27, 2012 4:14:13 PM UTC-5, Douglas
wrote:>
> This is driving me crazy. I''m trying to load the nodes array into
a
> puppet array with hiera. Hiera seems to always flatten an array or a
> hash to a string, with no delimiter in between, which makes it hard to
> split into an array later on.
>
> The hiera_hash and hiera_array functions only take a single key, so
> there''s no way that I can see to drill down into a multi level
yaml
> file like below.
>
> glusterfs_volumes:
> gfsvol01:
> master_server: gfs01.us1.xxx.com
> transport: tcp
> name: gfsvol01
> replicas: 1
> nodes:
> - gfs01.us1.xxx.com
> - gfs02.us1.xxx.com
> brick_store: /var/bricks
>
> How can I do this?
>
Hiera does not flatten arrays and hashes, but there are several ways you
can make Puppet do so after the value is loaded. What you describe sounds
exactly like what I would expect to see in such a case.
In the first place, you should normally use the hiera() function to
retrieve values of all types. The hiera_array() and hiera_hash() functions
are for collecting the values of the specified key across all levels of
your hierarchy, and returning them in array or hash form, respectively.
Among other things, that means that the structure of the values returned
from hiera_array() and hiera_hash() will *always* differ from the structure
the hiera() function would return for the same key: at minimum, the former
two functions wrap the value returned by the latter in an outer array or
hash.
What you are looking for is probably something like this:
$volumes = hiera(''glusterfs_volumes'')
$vol01 = $volumes[''gfsvol01'']
$v01_master = $vol01[''master_server'']
# I think this works, too:
$v01_transport =
$volumes[''gfsvol01''][''transport'']
etc.
Be sure not interpolate array or hash values into strings, or to assign
them to parameters that assume a string value; these are some of the ways
to inadvertently flatten your data.
John
--
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/-/B3XtW2hjYngJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.