On Wednesday, October 8, 2014 8:09:28 PM UTC-5, Stack Kororā wrote:

However, I did get it working and you reaffirmed something I had
discovered. So thank you very much for responding. I do appreciate it.
I'm glad you got it working.

Since the documentation is near rubbish on hiera, I started digging around
in the code itself for the hiera projects that _do_ work for me. I noticed
that there were two methods that seemed to pop up frequently.

1) The method Corey mentioned:
$bar = hiera('myfoo::bar', 'defaultvalue')

However, the puppet docs basically say do this for 2.7 but not for 3+ [
https://docs.puppetlabs.com/hiera/1/puppet.html ].

In Puppet 2, that was the only way you *could* do it. After Puppet 3 was
released, it was common for module authors to attempt to support both P2
and P3, which tied them to that form. Even with official support for the
P2 series ending, there is probably still interest in compatibility from
some quarters.

As for using *only* automatic parameter binding in P3, that's basically a
code style argument, its position right in the documentation
notwithstanding. The advice is not bad as far as it goes, but do note that
it also presents an apparently acceptable (albeit downplayed) alternative:
explicitly document the hiera keys your class uses. It seems like you've
probably been around enough to see a code-style war or two, so I'll leave
it there.

Also note that there are two examples on that page which completely fail
(silently...at least in my example code).
1.1) class myclass ( $parameter_one = hiera('myclass::parameter_one',
'default text')

That's hideous and wasteful (in current Puppet), but it ought to work.
Hiera calls (and other function calls) do work in class parameter lists,
unless there's been a regression I don't know about. In that particular
case, Puppet 3.x should perform two lookups of the same key. The only
reason to do it is for compatibility with Puppet 2.x, which does not have
automated data binding (and therefore will perform only one lookup).

1.2) class myclass ($parameter_one = "default text") { ...content =>
$parameter_one, ...}

[...] will /always/ go to 'default text' for me. It has yet to pull back
the hiera data.
If that's true then something is dreadfully wrong in your environment.
Class parameter defaults do not interfere with automated data binding.
Puppet's automated test suite verifies this, so if you're seeing different
behavior then there is some sort of local modification or environment issue
that is causing breakage. I hope you'll forgive me if I judge it more
likely that your tests are misleading you.

2) $ cat modules/testhiera/manifests/init.pp
class testhiera ( $test = $hieratest::test ) {
file { "/tmp/$test" : ensure => present}
How is that different from your 1.2, which you say doesn't work?

It seems like you may have a misconception: automated data binding applies
specifically to class *parameters*, as an aspect of resolving their
values. It does not apply to class variables that are not parameters, and
it is not automagically applied to parameters of classes that have not yet
been evaluated.

Your code (2) is dangerous for one of two reasons:

    1. If the code is written as you intended, then it relies for a class
    parameter default on a class variable of a different class, without doing
    anything to ensure that that other class (hieratest) has been evaluated.
    You can find extensive discussion of this issue and others related to using
    other classes' variables for parameter defaults by googling "puppet params
    class pattern".
    2. If you meant to write "class testhiera ( $test = $testhiera::test )",
    then you are specifying the default value for class parameter
    $teshiera::test to be itself. In that case, that default value will be
    used only in situations where it has not been intialized, so I think it's
    functionally equivalent to "class testhiera ( $test = undef )".

Either way, your code will work fine as long as the hiera lookup for your
class parameter succeeds (so that the default value is not consulted).
It's what will happen when the lookup accidentally or intentionally *fails*
that may come back to bite you in the assets.

But, its working now! Hooray!


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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/927e2cc1-3dd2-4cb9-a28a-d86be89a6c05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 9 of 16 | next ›
Discussion Overview
grouppuppet-users @
postedOct 8, '14 at 1:44p
activeOct 14, '14 at 7:50a



site design / logo © 2022 Grokbase