0

When running a Puppet plan that uses lookup{} function against Hiera I get the error:

The target node: 'computer1.domain.com' errored with a message: Internal Server Error: org.jruby.exceptions.RuntimeError: (PreformattedError) Evaluation Error: Error while evaluating a Method call, Could not find class ::- profile::app_update_3 for computer1.domain.com (file: /opt/puppetlabs/server/data/orchestration-services/code/environments/development/site-modules/profile/plans/package_install_plan.pp, line: 18, column: 40) on node computer1.domain.com

The plan class:

plan profile::package_install_plan (
  TargetSpec $targets,
){

  $targets.apply_prep

  $apply_results = apply($targets, '_catch_errors' => true) {
    lookup('classes', Array[String], 'unique').include
    
    #include profile::app_update_3
  }

  #return $apply_results
  $apply_results.each |$result| {
    $target = $result.target.name
   
    if $result.ok
    {
      out::message("The target node: '${target}' returned a value: ${result.message}")
      out::message("Target node: '${target}'. Report: ${result.report}")
    }
    else
    {
      out::message( "The target node: '${target}' errored with a message: ${result.error.message}")
    }
  }
}

My Hiera data is configured thus:

  • ./data/os/windows.yaml
  • ./data/nodes/computer1.domain.com.yaml

In windows.yaml, I have the lines:

classes:
  - profile::app_update_1

and in computer1.domain.com.yaml I have the lines:

classes:
  - profile::app_update_3

In the plan, if I use include profile::app_update_3 it works so I can't see the class is actually missing.

If I remove the defined classes: from computer1.domain.com.yaml, it works.

If I add the defined classes: to windows.yaml it works.

If it has something to do with arrays vs. strings in the plan lookup{} function, I have tried with multiple classes, although I believe in Yaml, XYZ: - Array1 is still an array.

I've checked there are no spurious characters in the Yaml that are upsetting things.

Specific node data works in other areas, so I assume my hiera.yaml is fine.

I've tried commenting out lookup('classes').include in .\manifests\site.pp in case that was interfering.

Here is Puppet's documented example (that uses the old hiera_include function).

Something else that I don't understand. When should I just use the class's name (app_update_3) and when should I include the full module's name (profile::app_update_3)? My guess is when the module is calling one of its own classes, I just use app_update_3, but it doesn't seem to work that way.

I've run out of ideas, so if anyone can put me on the right track, I'd be most grateful.

T.I.A

(Puppet Enterprise: v2019.8.4)

woter324
  • 233
  • 1
  • 3
  • 10

1 Answers1

0

It looks as though I wasn't doing anything wrong and the above is perfectly fine. In frustration, I re-wrote the computer1.domain.com.yaml file on a Linux system - which worked.

I then compared the two files and looking at the original in Notepad ++ I found this: enter image description here

Between the hyphen and 'profile' there is no character. How I typed no character, I have no idea. No amount of log eyeballing is going to find no character.

VSCode (Windows) seems happy now.

woter324
  • 233
  • 1
  • 3
  • 10