Hiera tool and hiera-puppet returns different data

79 views
Skip to first unread message

Vaidas Jablonskis

unread,
Dec 2, 2012, 11:15:01 AM12/2/12
to puppet...@googlegroups.com
Hi People,

I came across an issue where hiera command line tool returns a different data to what puppet3.0 builtin hiera does.

When I say different data, I mean hiera tool returns an array of items collected throughout the hierarchy, while hiera_array() called from within a manifest returns an array of items from the very top level of hierarchy.

Here is my setup example:

-----
node1.example.local.yaml:
foo::conf:
  - 'node_specific = foo'
  - 'node_specific2 = foo2'

common.yaml:
foo::conf:
  - 'common = foo'
  - 'common2 = foo2'
-----


That's what I get by running hiera tool on the puppet master:

# hiera -c /etc/puppet/hiera.yaml -a foo::conf environment='development' fqdn='node1.example.local'
["node_specific = foo", "node_specific2 = foo2", "common = foo", "common2 = foo2"]


From within the manifest, I use as a parameter:
$conf = hiera_array('foo::conf')

and then I have a template which creates a file on a node:
<% conf.each do |item| -%>
<%= item %>
<% end -%>

.. so what this template create is the following content of a file on node1:
node_specific = foo
node_specific2 = foo2

The node is in development environment.

What am I doing wrong? Is this some kind of bug or intentional behavior of puppet and hiera?

Thanks,
Vaidas

Vaidas Jablonskis

unread,
Dec 2, 2012, 11:36:40 AM12/2/12
to puppet...@googlegroups.com
Adding my hiera.yaml content:

# cat /etc/puppet/hiera.yaml 
---
:hierarchy:
  - %{environment}/nodes/%{fqdn}
  - %{environment}/roles/%{role}
  - %{environment}/common

:backends:
  - yaml
  #- puppet

:yaml:
  :datadir: '/etc/puppet/hieradata'

:puppet:
  :datasource: 'data'

Vaidas Jablonskis

unread,
Dec 2, 2012, 12:46:25 PM12/2/12
to puppet...@googlegroups.com

Vaidas Jablonskis

unread,
Dec 2, 2012, 4:03:49 PM12/2/12
to puppet...@googlegroups.com
See my issue report, I updated it with my finding. It seems to be a bug.

Vaidas Jablonskis

unread,
Dec 2, 2012, 5:19:24 PM12/2/12
to puppet...@googlegroups.com
wrong.

Thanks to reidmv and Volcane from #puppet @freenode for explaining this to me.

There is no easy way to use hiera_hash() or hiera_array() using the built-on hiera() lookup.

The easiest workaround in my case is to do something like this:



# class
class foo(
  $configuration = hiera_array('foo::conf', undef)
) {...}


# template
<% configuration.each do |item| -%>
<%= item %>
<% end -%>


# cat nodes/node1.example.local.yaml:
foo::conf:
  - 'node_specific = foo'
  - 'node_specific2 = foo2'

# cat common.yaml:
foo::conf:
  - 'common = foo'
  - 'common2 = foo2'

jcbollinger

unread,
Dec 3, 2012, 10:37:17 AM12/3/12
to puppet...@googlegroups.com


On Sunday, December 2, 2012 4:19:24 PM UTC-6, Vaidas Jablonskis wrote:
wrong.

Thanks to reidmv and Volcane from #puppet @freenode for explaining this to me.

There is no easy way to use hiera_hash() or hiera_array() using the built-on hiera() lookup.

The easiest workaround in my case is to do something like this:



# class
class foo(
  $configuration = hiera_array('foo::conf', undef)
) {...}


# template
<% configuration.each do |item| -%>
<%= item %>
<% end -%>


# cat nodes/node1.example.local.yaml:
foo::conf:
  - 'node_specific = foo'
  - 'node_specific2 = foo2'

# cat common.yaml:
foo::conf:
  - 'common = foo'
  - 'common2 = foo2'



So, yes, if you want the functionality of hiera_array() or hiera_hash() then you must call those functions.  Class parameter auto-lookup uses the hiera() function.  Personally, I would recommend always calling hiera(), hiera_array(), or hiera_hash() explicitly instead of parametrizing your classes and relying on autolookup.  It is clearer, and if you want compatibility with Puppet 2.7 then it's essential.  It also removes the false distinction that your classes appear to have if they need to use hiera_array() or hiera_hash() for some data, but plain hiera() for others.

Inasmuch as you should always declare classes via the 'include' or 'require' function anyway (not via the parametrized style), defining formal class parameters gains you little of consequence.


John

Reply all
Reply to author
Forward
0 new messages