Issues with Hiera command line usage with fact parameters

1,204 views
Skip to first unread message

Peter

unread,
Jan 9, 2014, 6:29:34 AM1/9/14
to puppet...@googlegroups.com
Hi List,

I am experimenting with different hiera hierarchy's through the hiera command line.  I am passing in different facts to simulate different nodes.  In the beginning I would manually pass them in as parameters on the command line after a while when I wanted to pass in more and more facts I decided to use the YAML scope file option.

This does not seem to work when I use the :: notation in the hieral.yaml under the hierarchy.  I have simplified my hierarchy to demonstrate the issue.  The relevant files look like:

**********************************************
$ ls -R
.:
facts.yaml  hiera.yaml  hieradata

./hieradata:
common.yaml  node

./hieradata/node:
creator.mgnt.local.yaml

**********************************************
 $ cat hiera.yaml
---
:backends:
  - yaml
:yaml:
  :datadir: ./hieradata
:hierarchy:
  - "node/%{::fqdn}"
  - common

**********************************************
$ cat hieradata/common.yaml
---
ip: '192.168.0.1'


**********************************************
$ cat hieradata/node/creator.mgnt.local.yaml
---
ip: '10.0.0.1'

**********************************************
$ cat facts.yaml
---
  fqdn: "creator.mgnt.local"

If I manually pass the facts on the command line it works

$ hiera -c hiera.yaml ip ::fqdn=creator.mgnt.local -d
DEBUG: 2014-01-09 22:19:48 +1100: Hiera YAML backend starting
DEBUG: 2014-01-09 22:19:48 +1100: Looking up ip in YAML backend
DEBUG: 2014-01-09 22:19:48 +1100: Looking for data source node/creator.mgnt.local
DEBUG: 2014-01-09 22:19:48 +1100: Found ip in node/creator.mgnt.local
10.0.0.1


However if I use a file which contains the facts it doesn't work

$ hiera -c hiera.yaml ip -y facts.yaml -d
DEBUG: 2014-01-09 22:26:31 +1100: Hiera YAML backend starting
DEBUG: 2014-01-09 22:26:31 +1100: Looking up ip in YAML backend
DEBUG: 2014-01-09 22:26:31 +1100: Looking for data source common
DEBUG: 2014-01-09 22:26:31 +1100: Found ip in common
192.168.0.1

In the facts file I have have tried it also declaring it like "::fqdn" but that also does not work.  Is there an option to bring the factor variables into the global scope?

Thanks,

Peter

Johan De Wit

unread,
Jan 9, 2014, 11:19:23 AM1/9/14
to puppet...@googlegroups.com
Hi,
Could it be something stupid like
---
  fqdn: puppet.koewacht.net

in your facts.yaml ?

I generated my facts.yaml from facter -y

Grts

Jo
--
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/420abd32-c607-4374-ad34-64c999487ed7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


-- 
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer         (805008667232363)
Puppet Certified Professional 2013 (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:

Puppet Fundamentals Training | http://www.open-future.be/puppet-fundamentals-training-4-till-6th-february

Puppet Introduction Course | http://www.open-future.be/puppet-introduction-course-7th-february

Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-10-till-12th-february

Zabbix for Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-13-till-14th-february

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


Peter

unread,
Jan 10, 2014, 6:32:16 AM1/10/14
to puppet...@googlegroups.com
Hi Johan,

Thanks for the suggestion, unfortunately it did not work.

It seems that using a scope file (http://docs.puppetlabs.com/hiera/1/command_line.html#json-and-yaml-scopes) doesn't load the facts into the global scope.  Could this be a hiera command line bug?

If I change the hiera.yaml hierarchy from "node/%{::fqdn}" to "node/%{fqdn}" it works.


Am I missing something?

Peter.

Johan De Wit

unread,
Jan 10, 2014, 1:46:24 PM1/10/14
to puppet...@googlegroups.com
Hi Peter,

It all depends wher you use variables.

In manifests, it is best practice to scope facts @ top scope (::), if you really want to use the fact

you can do something like this :
ipaddress => 192.168.10.0 (the fact)

class { 'x':

  $ipaddress = '10.0.0.0'

  notify { "fact = ${::ipaddress}, local is ${ipaddress} }

}

If you always scope your facts, you are sure that you use the fact variable.

And it is true that you don't use the scoping in the hiera.yaml file for facts.  I didn't noticed it

Glad it works now.

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

Vincent Deygas

unread,
Feb 23, 2017, 1:08:06 PM2/23/17
to Puppet Users
Hi,

Very old thread but if someone else is redirected here by a google search...
In my case, I used:

$ cat facts.yaml
---
  '::fqdn': "creator.mgnt.local"

And it worked.

Regards,
Vincent.
Reply all
Reply to author
Forward
0 new messages