Using hiera-data for a specific node

68 views
Skip to first unread message

Matthias Viehweger

unread,
Jul 23, 2014, 1:01:20 PM7/23/14
to puppet...@googlegroups.com
Hi list!

I have a problem integrating puppet and hiera.

Our puppet-master and all nodes are running puppet 3.6.2. On the master,
hiera version 1.3.4 is installed.

I want to use some hiera-data in a class depending on the node. To be
less abstract, I have this class:

  class memcached::server{
    $cap = hiera('memcached.cap', 64)

    # package and service omitted here

    if is_integer($cap) {
      file { '/etc/memcached.conf':
        ensure     => present,
        content    => template('memcached/memcached.conf.erb'),
        notify     => Service['memcached'];
      }
    } else {
      fail("memory \$cap should be an integer")
    }
  }

In a future refactoring, I may promote $cap to be a class-parameter
and also use the validation from the stdlib.

But first, I want to get 'memcached.cap' from a node-specific file.

Puppet is configured with "hiera_config = /etc/puppet/hiera.yaml".
The file /etc/puppet/hiera.yaml is as follows:

  ---
  :backends: yaml
  :yaml:
    :datadir: /var/lib/hiera
  :hierarchy:
    - %{clientcert}
    - common
  :logger: console

This is - from the docs - the internal default with just one hierarchy added.

I do not have the value "memcached.cap" in the /var/lib/hiera/common.yaml
I do have a file /var/lib/hiera/shop-01.hoster.de which contains

  memcached.cap: 256

Using this configs manually via the CLI, I get the expected result:

  $ sudo hiera memcached.cap -d -c /etc/puppet/hiera.yaml -y /var/lib/puppet/yaml/facts/shop-01.hoster.de.yaml
  DEBUG: Wed Jul 23 18:49:39 +0200 2014: Hiera YAML backend starting
  DEBUG: Wed Jul 23 18:49:39 +0200 2014: Looking up memcached.cap in YAML backend
  DEBUG: Wed Jul 23 18:49:39 +0200 2014: Looking for data source shop-01.hoster.de
  DEBUG: Wed Jul 23 18:49:39 +0200 2014: Found memcached.cap in shop-01.hoster.de
  256

So far, everything is nice. BTW, when I change the %{clientcert} to
%{::clientcert} is does work through the CLI anymore.

I cannot get the same data through puppet.

What am I doing wrong? Where - apart from the source-code - can I look
for information how that lookup works?

Thanks,
Matthias Viehweger

Atom Powers

unread,
Jul 23, 2014, 1:13:47 PM7/23/14
to puppet...@googlegroups.com
Is the value of "256" being resolved by puppet as a string?
That would cause your "is_integer" test to fail.


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/9933888a-1607-4473-87f2-e47439df844a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Perfection is just a word I use occasionally with mustard.
--Atom Powers--

Matthias Viehweger

unread,
Jul 23, 2014, 1:25:50 PM7/23/14
to puppet...@googlegroups.com
Am Mittwoch, 23. Juli 2014 19:13:47 UTC+2 schrieb Atom Powers:
Is the value of "256" being resolved by puppet as a string?
That would cause your "is_integer" test to fail.


Well, if that test fails, then my core problem - getting the data at all - is solved. 

I expect that the conversion from YAML-types to Puppet-types is lossless in this case, because ruby does the right thing here and puppet would need to make an effort to get it wrong ;-)

But that would be a nice catch. thanks, Atom Powers.
Reply all
Reply to author
Forward
0 new messages