Hiera not expanding $operatingsystem variable

72 views
Skip to first unread message

Karolis Pabijanskas

unread,
Jul 30, 2014, 12:21:18 PM7/30/14
to puppet...@googlegroups.com
Hi All,

I am sure this is going to be something completely stupid, but I just can't find the issue :)

I have a very simple module that that needs a different filepath depending on the operating system, so I'm trying to call:

$global_bashrc_file = hiera("global_bashrc_file")

from my module.

The hierarchy at the moment is very simple:

:hierarchy:
  - %{operatingsystem}
  - default

Calling notify from the module works just fine and brings back CentOS as my operating system. CentOS.yaml does exist in the  datadir and does contain the variable. Running hiera in through the shell does indeed show it working and returns the correct variable:

# hiera global_bashrc_file operatingsystem=CentOS
/etc/bashrc

But when trying to get this value via puppet, I just get an error:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find data item global_bashrc_file in any Hiera data file and no default supplied at blah

It does work perfectly fine if I place the variable in default.yaml, but if I move it to the os-specific yaml it just shouts at me that I have not declared it... Just seems like $operatingsystem does not get passed on from puppet, even though:
# facter operatingsystem
CentOS

and notify '{ "${operatingsystem": }' in puppet works.

As mentioned, I am sure I am missing something very trivial, but maybe one of you enlightened ones can point me in the right direction!

puppet version is 3.6.2
hiera version i 1.3.4

Thanks in advance!

Karolis

Johan De Wit

unread,
Jul 30, 2014, 1:24:02 PM7/30/14
to puppet...@googlegroups.com
Hi,

always use quotes when using facts etc in hiera :


:hierarchy:
  - "%{operatingsystem}"
  - default

hth

Johan
--
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/CANYNSSKRx_p2ZpG2JjJLYhRKtwwgtB-AReVozpUsovAF7dPG_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


-- 
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer              (805008667232363)
Puppet Certified Professional 2013/2014 (PCP0000006)
_________________________________________________________
 
Open-Future                 Phone     +32 (0)2/255 70 70
Zavelstraat 72              Fax       +32 (0)2/255 70 71
3071 KORTENBERG             Mobile    +32 (0)474/42 40 73
BELGIUM                     http://www.open-future.be
_________________________________________________________
 

Upcoming Events:

Linux Training | https://www.open-future.be/linux-training-8-till-12th-september

Puppet Introduction Course | https://www.open-future.be/puppet-introduction-course-15th-september

Puppet Fundamentals Training | https://www.open-future.be/puppet-fundamentals-training-16-till-18th-september

Zabbix Certified Specialist | https://www.open-future.be/zabbix-certified-specialisttraining-22-till-24th-september

Zabbix Certified Professional | https://www.open-future.be/zabbix-certified-professional-training-25-till-26th-september

Subscribe to our newsletter: http://eepurl.com/BUG8H


Garrett Honeycutt

unread,
Jul 30, 2014, 2:04:06 PM7/30/14
to puppet...@googlegroups.com
Hi,

Good eye on the quotes, Johan. Whenever you change hiera.yaml, be sure
to restart the puppet master.

Best regards,
-g




--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

Karolis Pabijanskas

unread,
Jul 30, 2014, 3:47:41 PM7/30/14
to puppet...@googlegroups.com
Thanks! I knew it was something simple! I just did not restart the puppet master.... that was all.. hiera works fine with or without the quotes though and they are not required.

Thanks again for the tip!

Karolis


--
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.

Christopher Wood

unread,
Jul 30, 2014, 4:03:26 PM7/30/14
to puppet...@googlegroups.com
On Wed, Jul 30, 2014 at 08:47:23PM +0100, Karolis Pabijanskas wrote:
> Thanks! I knew it was something simple! I just did not restart the puppet
> master.... that was all.. hiera works fine with or without the quotes
> though and they are not required.

I've had some troubles using all-numeric strings ("1234") unquoted in templates, where they are interpreted as integers. Not that I'm the expert, but it's worth considering that ruby variables in templates are typed, but puppet variables in manifests aren't, and will need more care when writing yaml for templates.

Consider how you'll need to use to_s or to_i in a template:

---
integer: 1234
string: "1234"

$ readyaml /tmp/yaml1
{"integer"=>1234, "string"=>"1234"}

Obviously I'm not the expert, it's just a bit of a pain.


$ cat bin/readyaml
#!/usr/bin/env ruby

require 'pp'
require 'yaml'

data = File.read(ARGV[0])
yaml = YAML.load(data)
pp yaml


> Thanks again for the tip!
>
> Karolis
>
> On 30 July 2014 19:03, Garrett Honeycutt <[1]g...@garretthoneycutt.com>
> Mobile: [2]+1.206.414.8658
> --
> 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 [3]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [4]https://groups.google.com/d/msgid/puppet-users/53D93388.9060604%40garretthoneycutt.com.
> For more options, visit [5]https://groups.google.com/d/optout.
>
> --
> 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 [6]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [7]https://groups.google.com/d/msgid/puppet-users/CANYNSSJAz1YOn6cnm0oSiG7KNehqu60TEyHq_hum2T5O97xycQ%40mail.gmail.com.
> For more options, visit [8]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. mailto:g...@garretthoneycutt.com
> 2. file:///tmp/tel:%2B1.206.414.8658
> 3. mailto:puppet-users%2Bunsu...@googlegroups.com
> 4. https://groups.google.com/d/msgid/puppet-users/53D93388.9060604%40garretthoneycutt.com
> 5. https://groups.google.com/d/optout
> 6. mailto:puppet-users...@googlegroups.com
> 7. https://groups.google.com/d/msgid/puppet-users/CANYNSSJAz1YOn6cnm0oSiG7KNehqu60TEyHq_hum2T5O97xycQ%40mail.gmail.com?utm_medium=email&utm_source=footer
> 8. https://groups.google.com/d/optout
Reply all
Reply to author
Forward
0 new messages