Overriding class options with hiera

109 views
Skip to first unread message

Bilco105

unread,
Dec 16, 2013, 10:53:49 AM12/16/13
to puppet...@googlegroups.com
Hi, 

I'm trying to do something with Hiera, whereby the 'default' configuration for a class is within it's role/profile manifest, which can then be overridden on a node specific basis by hiera.

As an example;

class profile::base {
  class { '::ntp':
    servers => ['a', 'b', 'c', 'd']
  }
}

node 'blah.com' {
  include profile::base
}

hieradata/nodes/blah.com.yaml:
---
ntp::servers:

However, I've noticed that hiera's behaviour seems to be that if a parameter is set like I do for the ntp::server param in the ntp class, it's not looked up (all the other NTP params are looked up in hiera, except for servers). Whereas if I just do:

class profile::base {
 class { '::ntp': }
}

The server parameter is now looked up from hiera.

Is this intended behaviour?

Thanks,
Rob

jcbollinger

unread,
Dec 16, 2013, 4:52:44 PM12/16/13
to puppet...@googlegroups.com


Yes.  If you specify a class parameter value in a parameterized-style class declaration then that value overrides anything available from hiera.  Hiera data, in turn, overrides any default value set in the class definition:

class ntp ($servers = ['e', 'f', 'g']) {
  # stuff
}

If you want site defaults that can be overridden for special nodes, then put the site defaults at a lower-priority level of your data hierarchy instead of in a class declaration.  Such hierarchical data are what hiera is all about.


John

Reply all
Reply to author
Forward
0 new messages