1

Hello everybody,

When I do puppet apply, I get the error:

Warning: Scope(Mod::Cl[title]): Can't load '/tmp/file.yaml' File does not exist! Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Operator '[]' is not applicable to an Undef Value. 

I specify that loadyaml is a function of stdlib module

However, i want to execute file resource before define resource

Someone can help me ?

 class mod::princ ( file { '/tmp/file.yaml': ensure => file, owner => 'root', group => 'root', mode => '0644', source => "puppet:///modules/othermod/file.yaml", before => Mod::Cl["title"], }-> Mod::Cl{ "title" : tmp_file => "/tmp/file.yaml", } } define mod::cl ( String $tmp_file, ){ $tmp = loadyaml("$tmp_file") $tmp[var].each |Integer $i, Hash[String,String] $var| { $mark=$var['Mark'] } } 
4
  • Are you using a Puppet master? Commented May 21, 2017 at 17:36
  • Thanks for the answer, with an apply or a Puppet master, I get the same error Commented May 21, 2017 at 18:00
  • Puppet first compiles the manifest and then applies it, but loadyaml (and other functions) run at compile time, while resources like file run at apply time. Read the file directly from the module (othermod/file.yaml), else explain what you're trying to achieve so we can help better - mod::cl doesn't appear to do anything. Commented May 22, 2017 at 8:31
  • Hello Dominic, thanks for the answer. In fact, I read the file yaml and rewrite another one from the define mod::cl. I already tried to read the file directly from the module (othermod/file.yaml), but it does not work. Commented May 22, 2017 at 13:15

1 Answer 1

0

As Dominic mentioned in his comment, the loadyaml function is run at compile-time.

If you are running Puppet via a Puppet Master/Server and puppet agent, this happens on the server, before the manifest is sent to the client, not on the client itself.

In addition, the loadyaml function is run at compile, not execution - so the file needs to exist before the Puppet run takes place.

I'd query why you're taking this approach with your Puppet code - you don't really explain what the code is for, or what your intended end-state looks like.

You can get the same results using Hiera.

hieradata/common.yaml

--- mod::princ::data: entry: foo: bar yrtne: oof: rab 

modules/mod/manifests/princ.pp

class mod::princ ( Hash $data ) { $data.each |Integer $i, Hash $elem, $var | { $mark=$var['Mark'] } } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.