Yes, it is that simple. The other way of doing (some people prefer this way actually) is to put your variables inside the actual class (not as parameters of the class), for example:
class foo { $my_parameter = hiera('foo::my_parameter', 'default_value') $another_parameter = hiera('foo::another_parameter', 'some default value') <...> } As you can see I didn't use any class parameters, I just put my variable inside the class and used hiera() funciton to fetch the values from hiera data. There are couple of things to understand here: 1. syntax of hiera() is: hiera('parameter_to_look_for', 'default_value_if_not_found') 2. the "parameter_to_look_for" can be anything you like, but the best practice is to keep it consistent, so for example you have a class 'foo' and a variable 'myvar' inside the class, then you should have it as 'foo::myvar' in hiera data files. Hope this helps. -- Vaidas On Tuesday, 4 December 2012 00:00:21 UTC, Pete wrote: > > On 3 December 2012 22:38, Vaidas Jablonskis <jablo...@gmail.com<javascript:> > > wrote: > >> Hi Pete, >> >> It depends on what version of puppet you use. If you use 3.x, then it has >> hiera built-in. So it's very simple to write classes which are compatible >> with v2.7 or v3.x versions. >> > > I am testing on 3. > > I normally write something like this: >> >> class foo( >> $parameter = undef, >> ) {...} >> > > Ah nice. > That's pretty logical. > I didn't think of doing that. > > What that means is that puppet will automatically call >> hiera('foo::parameter') and tries to find a value for $parameter in the >> hierarchy if it cannot find it, then the value of $parameter will be equal >> to undef. >> > > Ah I wasn't aware I could define vars like that in Hiera. > Is it as simple putting this in one of my data files? > > foo::parameter: value > > > Pete > > > >> >> On Monday, 3 December 2012 03:42:08 UTC, Pete wrote: >>> >>> Hi everyone, >>> >>> I currently have a giant file with default variables I use in a lot of >>> my modules and I override those at the node level if I need to. >>> I thought I would give porting that data into a hiera setup. >>> >>> I worked out how to specify my data sources and started to make a go at >>> moving some of my variables in the default data file. >>> >>> I thought heira would be smart and set a variable to undef if it >>> couldn't find it but that doesn't seem to be the case. (unless I missed >>> something in the rather sparse documentation) >>> Is there a way of telling it to do this? >>> >>> I was also trying to work out how I automagically get my parametized >>> classed to pull in vars from hiera. (The docs on that don't tell me much >>> either.) >>> Can anyone tall me how that works? Or do I have to use the hiera >>> functions which isn't automagical in my book. >>> >>> My current variables are set with a default value in my main file and >>> then I override those at the node level if I need to (so kind of the same >>> way hiera does it anyway) >>> >>> So given all of that I can't see any reason to switch to using heira >>> because my current setup works as-is (my variable file is getting pretty >>> huge anyway but that isn't going to change with heira if it won't set a var >>> to undef). >>> >>> What are the benefits or using an external source for variables instead >>> of sticking them in my node definitions (which seems like it would be >>> faster because it doesn't have to use an external source)? >>> >>> Thanks in advance. >>> Pete. >>> >> -- >> 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/-/PreiZnQjKIcJ. >> To post to this group, send email to puppet...@googlegroups.com<javascript:> >> . >> To unsubscribe from this group, send email to >> puppet-users...@googlegroups.com <javascript:>. >> For more options, visit this group at >> http://groups.google.com/group/puppet-users?hl=en. >> > > -- 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/-/ygahW1cKSLoJ. 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.