Working with hiera and debugging

149 views
Skip to first unread message

Alex Samad

unread,
Jun 26, 2016, 8:41:35 PM6/26/16
to Puppet Users
Hi

Newbie - greenfield install . Centos 6.8 - PC1 puppet. Master puppet setup.

I have installed R10K and git and hiera.

I would like to group my nodes into groups

I'm doing some testing

testnode  - puppet client
masternode  - puppet master

On the master node I have 


 cat /etc/puppetlabs/puppet/puppet.conf
# This file can be used to override the default puppet settings.
# See the following links for more details on what settings are available:
[master]
vardir = /opt/puppetlabs/server/data/puppetserver
logdir = /var/log/puppetlabs/puppetserver
rundir = /var/run/puppetlabs/puppetserver
pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid
codedir = /etc/puppetlabs/code

storeconfigs = true
storeconfigs_backend = puppetdb

reports = store,puppetdb


node_terminus = exec
external_nodes = /usr/local/bin/puppet_node_classifier




I was use a node classifier at the top level to place nodes into environments - but I am testing grouping nodes in to groups in 1 env/

all it produces is
---
environment: alex 


for now


cat /etc/puppetlabs/puppet/hiera.yaml
---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - common

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:



This is the default hiera setup 


cat /etc/puppetlabs/code/environments/alex/hieradata/common.yaml
---
classes:
       - profile::mypuppet

message: "This node is using common data"

#Puppet Server Tuning
puppet_enterprise::master::puppetserver::jruby_max_requests_per_instance: 0



cat /etc/puppetlabs/code/environments/alex/site/profile/manifests/mypuppet.pp
class profile::mypuppet {

        package { 'puppet-agent' :
                ensure => 'present',
        }

        #include ::puppet_agent;

}



then i go to my test node

# for testing ..
sudo /opt/puppetlabs/bin/puppet agent --noop --verbose -t
Notice: Local environment: 'production' doesn't match server specified node environment 'alex', switching agent to 'alex'.
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Applying configuration version 'ee80ea6b15178f517618992833a8bc3c7c378bd0'
Notice: Applied catalog in 0.04 seconds

I don't see any mention of mypuppet ??

Am i testing the system the right way ?
What am i doing wrong ?

Thanks
Alex







Peter Kristolaitis

unread,
Jun 26, 2016, 11:16:46 PM6/26/16
to puppet...@googlegroups.com

It's important to keep in mind that Hiera is "just data".  You still need to actually create the resources somehow in your manifest based on that data.

Thus, creating a data element called "classes" in Hiera isn't enough to actually get those classes applied to the node.  You need to add hiera_include('classes') in your manifest. More info here:  https://docs.puppet.com/hiera/3.1/puppet.html#assigning-classes-to-nodes-with-hiera-hierainclude

Having said that, until you get more experience with Puppet I would recommend avoiding using Hiera to assign classes to nodes.  It can be harder to debug and maintain, and breaks the rule of thumb that Hiera should only contain configuration data and not class structure.  You may want to look into the "roles and profiles" model instead.  There ARE valid reasons to assign classes via Hiera (e.g. assigning a role to the node based on the output of a custom Hiera backend) but this wouldn't be the approach I recommend to a newbie.  :)
--
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/a7bb4a4b-d61b-4db0-bdff-57030d75cb51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Samad

unread,
Jun 27, 2016, 12:23:38 AM6/27/16
to puppet...@googlegroups.com
Hi

Okay, i do it a bit simpler :)

/etc/puppetlabs/puppet/hiera.yaml

i added

message: "This node is using global common data"

sudo /opt/puppetlabs/bin/puppet agent --noop --verbose -t

didn't see the text message !
> You received this message because you are subscribed to a topic in the
> Google Groups "Puppet Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/puppet-users/OAtIhSwbyEs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/cb352a0f-20a3-c79c-ada2-fe717850ebff%40alter3d.ca.

Rob Nelson

unread,
Jun 27, 2016, 12:33:40 AM6/27/16
to puppet...@googlegroups.com
Have you tried the Learning Puppet VM? I believe it provides answers this and many of the other questions you have had over the past few weeks. There's really nothing better than actually trying to use the software to learn it.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAJ%2BQ1PUt6kDMRVveYmZwcYHMmVySK0i05Fed%2BPkY2H-pTrmmTA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--

Alex Samad

unread,
Jun 27, 2016, 12:36:34 AM6/27/16
to puppet...@googlegroups.com
I have... but then i spent 2-3 weeks doing git and r10k ...

I will look again..
> https://groups.google.com/d/msgid/puppet-users/CAC76iT-p5jMTzF%2BDg0o%3DzES985ciOVUePtnraFwPM4_36BqDog%40mail.gmail.com.

Peter Kristolaitis

unread,
Jun 27, 2016, 12:56:13 AM6/27/16
to puppet...@googlegroups.com
You may want to go back and re-read my previous message.

You're missing the very, very critical distinction that Hiera is not
your node manifest. Hiera is just data, and does not configure any
resources for the agent to manage. You still need to write your node
manifest files. Note that this differs from a class manifest.

Alex Samad

unread,
Jun 27, 2016, 3:02:31 AM6/27/16
to puppet...@googlegroups.com
Hi

Okay, I have downloaded and will re do he trainging VM.

But I have finished the reading this blog
http://www.craigdunn.org/2012/05/239/ << suggested to me here.

This is basically what i am trying to do. But I would like to see /
test what I am doing along the way

The install of puppet / hiera was by the documentation .

I have added in an ENC - only so I can allocate (in on place) node to
environments and potentially ??

I have a test node and I try the puppet agent -t --noop --verbose
hoping to see some results of my work on the puppet master.

I have seen - cert request and I have signed this.

Now this is what I am probably missing is the link in the production
environment to the class list - via roles / profiles ?

I am presuming I need to look at work with
/etc/puppetlabs/code/environments/production/manifests/site.pp
and get that to work with hiera ..

Alex
> https://groups.google.com/d/msgid/puppet-users/5ba1e92d-4464-15a9-fdd6-bea433b554c3%40alter3d.ca.

Alex Samad

unread,
Jul 2, 2016, 2:21:03 AM7/2/16
to Puppet Users
Incase somebody googles to here


i found this

puppet apply --certname=<abc> -e  "notice(hiera('classes'))" --noop --verbose

This shows me what the puppet master is giving as classes for a specific node based on certname.

also 

hiera  -d   classes   ::osfamily=RedHat environment=production   ::trusted.certname=<abc>


on the puppet master to give you info from hiera .. helpful
>>> To view this discussion on the web visit
>>>
>>> https://groups.google.com/d/msgid/puppet-users/a7bb4a4b-d61b-4db0-bdff-57030d75cb51%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Puppet Users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/puppet-users/OAtIhSwbyEs/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> To view this discussion on the web visit
>>>
>>> https://groups.google.com/d/msgid/puppet-users/cb352a0f-20a3-c79c-ada2-fe717850ebff%40alter3d.ca.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Puppet Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/puppet-users/OAtIhSwbyEs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

jcbollinger

unread,
Jul 5, 2016, 9:32:30 AM7/5/16
to Puppet Users


On Saturday, July 2, 2016 at 1:21:03 AM UTC-5, Alex Samad wrote:
Incase somebody googles to here


i found this

puppet apply --certname=<abc> -e  "notice(hiera('classes'))" --noop --verbose

This shows me what the puppet master is giving as classes for a specific node based on certname.


Clarification: (1) if run on the master, that command gives (2) the value that the master sees for Hiera key "classes" for the designated node, (3) as computed without benefit of that node's facts.  That key is commonly used to designated names of classes to be applied, but (4) that's a convention, not a rule, and (5) either way, there may be other classes applied, too.

 
also 

hiera  -d   classes   ::osfamily=RedHat environment=production   ::trusted.certname=<abc>


on the puppet master to give you info from hiera .. helpful


Indeed it does, and indeed it is.  Note that when Hiera is run from the command line like that, it uses only the fact values you specify on the command line, as shown.  Which fact values are significant depends on your hierarchy configuration and data.


John

Alex Samad

unread,
Jul 5, 2016, 6:44:41 PM7/5/16
to puppet...@googlegroups.com
Hi



On 5 July 2016 at 23:32, jcbollinger <John.Bo...@stjude.org> wrote:
>
>
> On Saturday, July 2, 2016 at 1:21:03 AM UTC-5, Alex Samad wrote:
>>
>> Incase somebody googles to here
>>
>>
>> i found this
>>
>> puppet apply --certname=<abc> -e "notice(hiera('classes'))" --noop
>> --verbose
>>
>> This shows me what the puppet master is giving as classes for a specific
>> node based on certname.
>
>
>
> Clarification: (1) if run on the master, that command gives (2) the value
> that the master sees for Hiera key "classes" for the designated node, (3) as
> computed without benefit of that node's facts. That key is commonly used to
> designated names of classes to be applied, but (4) that's a convention, not
> a rule, and (5) either way, there may be other classes applied, too.

Yes i seem to be running into these limitations.

So how does one debug..

I have my hiera setup the way I think i want to progress

:hierarchy:
# node specific
- "nodes/%{::trusted.certname}"
# OS specific
- "os/%{::osfamily}"
# Envornment - YB
- "ybenv/%{::ybenv}"
# common to all
- common


I want to group nodes based in a ybenv variable.


I have added this to my ENC i get this from it

---
environment: production
ybenv: alextest


I have add something to my hieradata/ybenv/alextest.yaml but it
doesn't seem to be working

But on the test node I try -t --noop --verbose. but it doesn't give me
any info about this.

Where can I look / what can I turn on to confirm that puppet / hiera
is looking at that file

I have also tried the hiera -d but it doesn't tell me all the yaml
files it touches.

Thanks
A


>
>
>>
>> also
>>
>> hiera -d classes ::osfamily=RedHat environment=production
>> ::trusted.certname=<abc>
>>
>>
>> on the puppet master to give you info from hiera .. helpful
>
>
>
> Indeed it does, and indeed it is. Note that when Hiera is run from the
> command line like that, it uses only the fact values you specify on the
> command line, as shown. Which fact values are significant depends on your
> hierarchy configuration and data.
>
>
> John
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Puppet Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/puppet-users/OAtIhSwbyEs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/663a9cc9-320b-43f0-9513-f52ce806728d%40googlegroups.com.

Alex Samad

unread,
Jul 5, 2016, 7:31:03 PM7/5/16
to puppet...@googlegroups.com
On 6 July 2016 at 08:44, Alex Samad <al...@samad.com.au> wrote:
> But on the test node I try -t --noop --verbose. but it doesn't give me
> any info about this.

Seems like I got that wrong, just applied -d to one of my test
commands on a test node and it has spewed out lots of info ...

Alex Samad

unread,
Jul 6, 2016, 1:28:59 AM7/6/16
to Puppet Users
Hi

Another update - again for any one else that comes to this thread.


found this can find the link i found it on :(

 /*
  notice("try to run this script with -v and -d to see difference between log levels")
  notice("function documentation is available here: http://docs.puppetlabs.com/references/latest/function.html")
  notice("--------------------------------------------------------------------------")

  debug("this is debug. visible only with -d or --debug")
  info("this is info. visible only with -v or --verbose or -d or --debug")
  alert("this is alert. always visible")
  crit("this is crit. always visible")
  emerg("this is emerg. always visible")
  err("this is err. always visible")
  warning("and this is warning. always visible")
  notice("this is notice. always visible")
  #fail will break execution
  #  fail("this is fail. always visible. fail will break execution process")
  */

I have been smattering these and notify around my code to find out what happening.

This and hiera and puppet agent -t --noop -d -v has been helping..


found this also
Reply all
Reply to author
Forward
0 new messages