Greetings,
I don't know why, but I am having a
rough time trying to get hiera to work. It seems to me that all the
examples I see online are either absurdly complex or so stupidly
simple that they are absolutely useless. Either way I have found the
documentation for hiera completely lacking (it doesn't help that
there is a lot of bad information pertaining old puppet releases that
is no longer the correct way to do things...at least according to
other sources which may or may not be the correct way either...bleck...). Of all the
documentation/blogs/examples/ect I have been pouring over the last 2
hours, not one has given me a useful hint at getting this working.
*deep breath in an attempt to control my frustration so I can communicate on a somewhat intelligent level*
Whew...
OK. Lets start.
$ puppet -V
3.7.1
$ hiera -V
1.3.4
$ hostname
puppet.test.vm
$ sudo puppet cert list --all
+ "puppet.test.vm" <snip blah blah string>
This is as simple as I can make it.
$ cd /etc/puppet
$ find . -type f
./modules/testhiera/manifests/init.pp
./manifests/site.pp
./puppet.conf <- did not touch after test vm install
./auth.conf <- did not touch after test vm install
$ cat manifests/site.pp
node 'puppet.test.vm' {
class { 'testhiera': }
}
$ cat modules/testhiera/manifests/init.pp
class testhiera ( $test="blah") {
file { "/tmp/$test" : ensure => present}
}
$ puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet.test.vm
Info: Applying configuration version '1412771807'
Notice: /Stage[main]/Testhiera/File[/tmp/blah]/ensure: created
Notice: Finished catalog run in 0.04 seconds
$ rm /tmp/blah
Hooray! That works. Can't get much simpler then that, right? OK, lets add in hiera. Should be simple right? Ha!
$ sudo ln -s /etc/puppet/hiera.yaml /etc/hiera.yaml
$ find . -type f
./hiera.yaml
./hosts/puppet.test.vm.yaml
./modules/testhiera/manifests/init.pp
./manifests/site.pp
./puppet.conf
./auth.conf
# Only added these two files below; made no other changes
$ cat hiera.yaml
---
:hierarchy:
- hosts/%{clientcert}
:backends:
- yaml
:yaml:
:datadir: '/etc/puppet/'
$ cat hosts/puppet.test.vm.yaml
---
hieratest::test: yadda
$ hiera hieratest::test clientcert=puppet.test.vm
yadda
# Hiera on the command line works. I must be making progress!!
$ sudo puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet.test.vm
Info: Applying configuration version '1412771807'
Notice: /Stage[main]/Testhiera/File[/tmp/blah]/ensure: created
Notice: Finished catalog run in 0.03 seconds
What??? That is absolutely contrary to
the documentation! It should have created /tmp/yadda! I am looking at
the official docs right now on using a hiera variable with a default variable and I don't see how my example is any
different in the slightest! Blah should have only been used as a
default if the host wasn't found. Clearly either puppet can't find
hiera and used default, or it simply ignored the hiera data.
Fine. We will take out the default blah
and force it to use something from hiera.
$ rm /tmp/blah
$ cat modules/testhiera/manifests/init.pp
class testhiera ( ) {
file { "/tmp/$test" : ensure => present}
}
$ sudo puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet.test.vm
Info: Applying configuration version '1412773578'
Notice: Finished catalog run in 0.04 seconds
What? No blah, no yadda, nothing! I don't even get an error!!
OK. OK. Fine. Maybe it doesn't like something in hiera. I will give hiera a default.
$ find . -type f
./hiera.yaml
./modules/testhiera/manifests/init.pp
./puppet.conf
./hosts/common.yaml
./hosts/puppet.test.vm.yaml
./auth.conf
./manifests/site.pp
$ cat hiera.yaml
---
:hierarchy:
- hosts/%{clientcert}
- hosts/common
:backends:
- yaml
:yaml:
:datadir: '/etc/puppet/'
$ cat hosts/common.yaml
---
hieratest::test: blarg
$ hiera hieratest::test clientcert=puppet.test.vm
yadda
$ hiera hieratest::test clientcert=some.thing.else
blarg
Yeah...alright...hiera on the command line is giving me exactly what I want. I have feeling good about this one...
$ sudo puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet.test.vm
Info: Applying configuration version '1412773578'
Notice: Finished catalog run in 0.06 seconds
$ ls /tmp/blah /tmp/yadda /tmp/blarg
ls: cannot access /tmp/blah: No such file or directory
ls: cannot access /tmp/yadda: No such file or directory
ls: cannot access /tmp/blarg: No such file or directory
ACK!!!! What the hell?!?!! Nothing? Not even an error?? Even running –debug on that puppet run gives me jack-squat of information. There isn't anything in the puppet master logs either.
I have tried doing the hiera_include (even though several places say don't though they fail to mention why not). I have tried doing $t2 = hiera('test') and creating /tmp/$t2 and that still gave me nothing. I have tried referencing it by full scope hieradata::test (again, even though the docs say don't do this) and still nothing.
Clearly, the hiera data works because it gives me exactly what I want on the command line. Puppet just seems to flat out ignore it. I can't get any of the examples to work.
HOWEVER, I tested a few of the puppet forge programs and THEY can reference their hiera data just fine! Oh that really got me riled up...So it isn't puppet because it works with their code. It has to be something in my code. So I reset the VM back to my code and I fail to understand why my incredibly simple code isn't working and I am seriously frustrated why I can't get any of the official documentation examples to work either.
I need to go take a break from
this...but I would be so very very grateful if someone could point
out where I am going wrong. Hiera works, but Puppet+Hiera doesn't and
I just don't understand why...Since the puppet forge code works, it *must* be something I have/haven't done but I can not seem to find it. The docs certainly aren't helping either. Any pointers/tips/examples/information would be greatly appreciated.
Thanks!
~Stack~
- hosts/%{fqdn}
Greetings,
I don't know why, but I am having a rough time trying to get hiera to work. It seems to me that all the examples I see online are either absurdly complex or so stupidly simple that they are absolutely useless. Either way I have found the documentation for hiera completely lacking (it doesn't help that there is a lot of bad information pertaining old puppet releases that is no longer the correct way to do things...at least according to other sources which may or may not be the correct way either...bleck...). Of all the documentation/blogs/examples/ect I have been pouring over the last 2 hours, not one has given me a useful hint at getting this working.
*deep breath in an attempt to control my frustration so I can communicate on a somewhat intelligent level*
Whew...
OK. Lets start.
$ hiera hieratest::test clientcert=puppet.test.vm
yadda
# Hiera on the command line works. I must be making progress!!
$ sudo puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet.test.vm
Info: Applying configuration version '1412771807'
Notice: /Stage[main]/Testhiera/File[/tmp/blah]/ensure: created
Notice: Finished catalog run in 0.03 seconds
What??? That is absolutely contrary to the documentation! It should have created /tmp/yadda!
I am looking at the official docs right now on using a hiera variable with a default variable and I don't see how my example is any different in the slightest! Blah should have only been used as a default if the host wasn't found. Clearly either puppet can't find hiera and used default, or it simply ignored the hiera data.
Fine. We will take out the default blah and force it to use something from hiera.
$ rm /tmp/blah
$ cat modules/testhiera/manifests/init.pp
class testhiera ( ) {
file { "/tmp/$test" : ensure => present}
}
$ sudo puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet.test.vm
Info: Applying configuration version '1412773578'
Notice: Finished catalog run in 0.04 seconds
What? No blah, no yadda, nothing! I don't even get an error!!
OK. OK. Fine. Maybe it doesn't like something in hiera. I will give hiera a default.
However, I did get it working and you reaffirmed something I had discovered. So thank you very much for responding. I do appreciate it.
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 ].
Also note that there are two examples on that page which completely fail (silently...at least in my example code).
THIS DOESN'T WORK:
1.1) class myclass ( $parameter_one = hiera('myclass::parameter_one', 'default text')
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.
2) $ cat modules/testhiera/manifests/init.pp
class testhiera ( $test = $hieratest::test ) {
file { "/tmp/$test" : ensure => present}
}
But, its working now! Hooray!
Wow! Thanks for the responses John!
> On Thursday, October 9, 2014 8:52:00 AM UTC-5, jcbollinger wrote:
> If the master had successfully looked up your datum then the result would
> have been as you expected. The behavior you present is characteristic of
> (and well documented for) the case where the automatic lookup fails,
> leaving the master to fall back to the default value given in the class
> definition. The problem is not in your Puppet manifests, and your CLI
> tests demonstrate that it is not in your data themselves, but those are not
> the only possibilities.
If it isn't hiera and it isn't puppet, what other possibilities are there? Any idea on how I can debug this better? I would love to see in the puppet logs something like "found a variable with no definition, looking up in hiera in this file...nope didn't find it...trying this other file...ah found it" but I haven't seen anything on how to better troubleshoot /how/ puppet is determining if a variable is in hiera or not.
>> 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.
Hrm...that's not good. But this test VM is a very new build of Scientific Linux 6.5 with the latest puppet. I really haven't made many changes. Not sure what I could have goofed on it. Any suggestions for debugging what is wrong? I mean nothing is really being kicked out in the log files (but that doesn't mean there isn't a problem).
>> 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?
Not sure i understand your question.
The 1.2 that doesn't work I am setting a default value in hopes that the hiera value is taken. In this example, I am explicitly calling the hiera value...Now functionally it may be the same (or at least it is supposed to be), but that isn't how I see it behave.
Even if the agent runs as root, there can still be access controls (e.g. SELinux policy) that prevent it from reading certain files that can be read by commands you launch directly from a shell.