Puppet Hiera isn't resolving Facts

Puppet Hiera isn't resolving Facts,puppet,hiera,Puppet,Hiera,I'm having some trouble with Puppet and Hiera, in that Hiera seems to not be using the facts I ask for in the templates. I have a /etc/puppetlabs/puppet/hiera.yaml file, with a simple sample hierarchy in it: --- version: 5 defaults: datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata" data_hash: yaml_data hierarchy: - name: "Per-node data" path: "nodes/%{trusted.certname}.yaml" - name: "Per-OS defaults" path: "os/%{facts.os.family}.yaml" - name: "Common

I'm having some trouble with Puppet and Hiera, in that Hiera seems to not be using the facts I ask for in the templates.

I have a

/etc/puppetlabs/puppet/hiera.yaml
file, with a simple sample hierarchy in it:

---
version: 5

defaults:
  datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata"
  data_hash: yaml_data

hierarchy:
  - name: "Per-node data"
    path: "nodes/%{trusted.certname}.yaml"

  - name: "Per-OS defaults"
    path: "os/%{facts.os.family}.yaml"

  - name: "Common data"
    path: "common.yaml"

I then have a puppet agent which has run and sent it's facts to Puppet. When I test a lookup on it, the variables all expand out to empty strings:

> puppet lookup profiles --environment production --node puppet.example.local --explain

Searching for "lookup_options"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Merge strategy hash
      Hierarchy entry "Per-node data"
        Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/test-.yaml"
          Original path: "nodes/test-%{trusted.certname}.yaml"
          Path not found
      Hierarchy entry "Per-OS defaults"
        Path "/etc/puppetlabs/code/environments/production/hieradata/os/.yaml"
          Original path: "os/%{facts.os.family}.yaml"
          Path not found
      Hierarchy entry "Common data"
        Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
          Original path: "common.yaml"
          No such key: "lookup_options"
Searching for "profiles"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Hierarchy entry "Per-node data"
      Path "/etc/puppetlabs/code/environments/production/hieradata/nodes/.yaml"
        Original path: "nodes/test-%{trusted.certname}.yaml"
        Path not found
    Hierarchy entry "Per-OS defaults"
      Path "/etc/puppetlabs/code/environments/production/hieradata/os/.yaml"
        Original path: "os/%{facts.os.family}.yaml"
        Path not found
    Hierarchy entry "Common data"
      Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
        Original path: "common.yaml"
        No such key: "profiles"
Function lookup() did not find a value for the name 'profiles'

The value isn't found, but I figure that's irrelevant because it isn't even looking for any real files, that are all showing as

nodes/.yaml
and
os/.yaml
.

If I run the command again with

--debug
, I can see a dump of information about the node that includes the facts:

Debug: Facter: fact "osfamily" has resolved to "RedHat".
...
Debug: Facter: fact "os" has resolved to {
  architecture => "x86_64",
  family => "RedHat",
  hardware => "x86_64",
  name => "CentOS",
  release => {
    full => "7.4.1708",
    major => "7",
    minor => "4"
  },

Puppet: 5.4.0


#1

Have your facts file specified in the following path

/etc/facter/facts.d/${your_component_facts}.sh

and give required permissions:

chmod +x /etc/facter/facts.d/${your_component_facts}.sh

#2

This is Facter 3.x?

#3

@MattSchuchard facter --version says 3.10.0.

#4

You are not specifying any facts on the command line. The puppet lookup command will obtain and use the most recent facts for the specified node if they are recorded in puppetdb and the command is run on a node that has access. It does not collect facts automatically as puppet agent or puppet apply would do.