Hiera unable to retrieve the value

1,665 views
Skip to first unread message

linuxbsdfreak

unread,
Aug 16, 2012, 11:25:17 AM8/16/12
to puppet...@googlegroups.com
Hi All,

I am using hiera for storing configuration values. I have setup puppet to use facter following the article from

http://nuknad.com/2011/02/11/self-classifying-puppet-nodes/

I have custom facts

company_role
company_platform
company_location

I have defined the following in hiera.yaml

---
:backends:
     - yaml

:logger: console

:hierarchy:
          - '%{operatingsystem}'
          - '%{platform}/%{location}/%{role}'
          - common

:yaml:
    :datadir: '/etc/puppet/hieradata'


and i create the directories /etc/puppet/hieradata/production/london/dev_tst.yaml

I have something like this in the above file

---

hsflowd_port: 8080

company_role: dev_tst
company_platform: production
company_location: london

Given a system with the above facts connecting to puppetmaster. When i run the client i get the following error

Err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find data item hsflowd_port in any Hiera data file and no default supplied at /etc/puppet/modules/hsflowd/manifests/config.pp.


For some reason its not getting the value. However when i do the following from the command line

hiera -c /etc/puppet/hiera.yaml hsflowd_port platform=production  location=frankfurt role=dev_tst

I get the value.

Following is my manifest:

class hsflowd::config(
  $hsflowd_user       = hiera('hsflowd_user'),
  $hsflowd_group      = hiera('hsflowd_group'),
  $hsflowd_config_dir = hiera('hsflowd_config_dir'),
  $hsflowd_port      = hiera('hsflowd_port'),
)

{

       file {
          "${hsflowd_config_dir}/hsflowd.conf":
                ensure  => present,
                content => template("${module_name}/hsflowd.conf.erb"),
                owner   => $hsflowd_user,
                group   => $hsflowd_group,
                mode    => '0644';
}

Is something wrong that i am doing?

Regards,
Kevin


linuxbsdfreak

unread,
Aug 16, 2012, 11:38:30 AM8/16/12
to puppet...@googlegroups.com
Typo error location=frankfurt is actually location=london.

denmat

unread,
Aug 16, 2012, 8:57:03 PM8/16/12
to puppet...@googlegroups.com
Hi, 

Can't see anything that stands out in the quick glance, but here's how you can dig further:

Use --debug on your puppet run and you'll get an output of what hiera is going through. Second, use notify to print out the variables you are trying to access, making sure they match with what hiera is looking for and what you expect. You can also try setting the default for the hsflowd_port and see if that solves your problems or there are others (not saying you should only use the default, just to further your own investigations).

  $hsflowd_port      = hiera('hsflowd_port', '8080'),
  
HTH,
Den
--
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/-/L2PKd1u1QAgJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

linuxbsdfreak

unread,
Aug 17, 2012, 3:28:13 AM8/17/12
to puppet...@googlegroups.com
Hi,

The default value works when i set the value in common.yaml. Strange part is why isnt hiera find the value in the hierarchy, since i want to override the default value according to a facter fact.

Regards,
Kevin

linuxbsdfreak

unread,
Aug 17, 2012, 5:31:40 AM8/17/12
to puppet...@googlegroups.com
Just for info i am running ruby-1.9.3p194.

denmat

unread,
Aug 17, 2012, 6:13:37 AM8/17/12
to puppet...@googlegroups.com

Sorry, your hiera config points to:


           -'%{operatingsystem}'
          - '%{platform}/%{location}/%{role}

          - common role

But the facts you have are:
company_role
company_platform
company_location

So unless you have facts platform, location, and role defined they aren't going to match up. It's like the facts you've used below:

hiera -c /etc/puppet/hiera.yaml hsflowd_port platform=production  location=frankfurt role=dev_tst

So role = dev_tst does not equal custom_role = dev_tst

-- you get what I mean?

Something like this might work:
          -'%{operatingsystem}'
          - %{custom_platform}/%{custom_location}/%{custom_role}


          - '%{platform}/%{location}/%{role}'

See if that works,
Den

To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/3rPfzeEvIMUJ.

linuxbsdfreak

unread,
Aug 17, 2012, 6:52:38 AM8/17/12
to puppet...@googlegroups.com
Hi,

I figured that out and did the changes to verify. However it doesn't parse the hierarchy to override the values. I did a quick test to only use the operatingsystem fact in hierarchy.  It doesnt pickup the value from it also. Even though the machine is CentOS.  I dont know if  hiera 0.3.0 works with ruby1.9.3

Regards,
Kevin

Evan Stachowiak

unread,
Aug 22, 2012, 3:44:21 PM8/22/12
to puppet...@googlegroups.com
I'm running into the same issue on Ubuntu 10.04, hiera 0.3.0, puppet 2.7.18, ruby187.

Hiera can lookup values, but only if there is no variable interpolation in /etc/puppet/hiera.yaml.

:hierarchy:
- '%{operatingsystem}'
- common

will give this error:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert nil into String

while

:hierarchy:
- common

works without any errors.

I also ran into this trying to setup hiera to use different hieradata directories based on environment.

:yaml:
- '/etc/puppet/environments/production/hieradata'

works properly.

:yaml:
- 'etc/puppet/environments/%{environment}/hieradata'

will give the same error:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert nil into String

Thanks,
Evan

Evan Stachowiak

unread,
Aug 23, 2012, 11:21:34 AM8/23/12
to puppet...@googlegroups.com
I managed to sort this out by checking out the latest hiera-puppet and upgrading the hiera & hiera-puppet gems to 1.0.1.0rc4 & 1.01.0rc3 respectively.

After updating hiera-puppet, be sure to restart the puppet master. If you do not update hiera & hiera-puppet gems, you may encounter the error: “no such file to load — hiera_puppet”.  This issue is documented in the following bug report:
http://projects.puppetlabs.com/issues/15570

To update your hiera gems run:
gem install hiera hiera-puppet --pre
(pre will install the release candidates instead of 0.0.3)

-Evan
Reply all
Reply to author
Forward
0 new messages