0

I'm coming from Puppet 3 and try to rebuild my code on a new Puppet 6 system. I try to give my Agentnodes some sort of "stage_level" like productive or testing. Hiera can't find this stage_level although it is set in a Hiera file.

The stage_level is set in my Nodedefinition and Hiera should be able to find it. The lookup itself is in the init.pp from a Module "Facter" which deploys three files on the Agentnodes.

hiera.yaml

version: 5
defaults:
datadir: /etc/puppetlabs/code/environments/production/data/
data_hash: yaml_data
hierarchy:
- name: 'Global Config'
  path: global.yaml
- name: 'Nodes'
  path: 'nodes/%{trusted.certname}.yaml'

A Nodedefinition in data/nodes/server.xyz.com.yaml

role: xyz
stage_level: production

init.pp from modules/facter/manifests/

define facter::set_av_facter {

$facter_value = hiera($name,'no_default_value')

file { "/etc/facter/facts.d/${name}.yaml":
  ensure  => present,
  owner   => 'root',
  group   => 'root',
  mode    => '0644',
  content => inline_template("# This file is managed by puppet\n${name}: ${facter_value}\n"),
     }
}

class facter {

file { '/etc/facter':
  ensure  => directory,
  owner   => 'root',
  group   => 'root',
  mode    => '0755',
 }

file { '/etc/facter/facts.d':
  ensure  => directory,
  owner   => 'root',
  group   => 'root',
  mode    => '0755',
}

$av_facter =  [
  'role',
  'stage_level',
]

facter::set_av_facter{$av_facter:}

file { "/etc/facter/facts.d/patchlevel.yaml":
  ensure => absent,
     }
}

Hiera can't find the stage_level that i set in the Nodedefinition. I think the problem is in the define, which i had to rewrite because this was actually code from Puppet 3. Expected outcome is a file on my Agentnode under /etc/facts/facter.d/stage_level.yaml with "production" as content.

Any help is appreciated

heat
  • 1
  • 1
  • 1
    Just to clarify do you really have all your code in the init.pp file? I think that's not allowed in Puppet 6. – Alex Harvey May 28 '19 at 15:17
  • For that module, yes. I will try to outsource the define to a different file. – heat May 29 '19 at 08:01
  • 1
    The title asks about the `lookup()` function, but the code presented uses `hiera()`, which is deprecated in Puppet 6 (and also in Puppet 5). `hiera()`'s documentation explicitly states that it does not provide the full functionality of `lookup()`, though it's not clear to me whether that's affecting you here. As long as you are working on this code already, this is the time to switch to `lookup()`, even if that doesn't resolve your present issue. – John Bollinger May 29 '19 at 11:56
  • 1
    I can't reproduce this based on the code sample above. You'll need to provide something that is reproducible before we can assist. – Alex Harvey May 29 '19 at 14:48

0 Answers0