Puppet包含不符合工作顺序的类包含

Puppet包含不符合工作顺序的类包含,puppet,erb,Puppet,Erb,我试图强制创建一个文件的Puppet类在另一个需要该文件存在才能正常运行的类之前进行处理。在木偶文章之后,我使用了contain 我的代码不起作用,我不明白为什么。它给出了以下错误: Error: Evaluation Error: Error while evaluating a Function Call, Failed to parse template testing/def.erb: Filepath: /root/local/testing/templates/def.erb

我试图强制创建一个文件的Puppet类在另一个需要该文件存在才能正常运行的类之前进行处理。在木偶文章之后,我使用了
contain

我的代码不起作用,我不明白为什么。它给出了以下错误:

Error: Evaluation Error: Error while evaluating a Function Call, Failed to parse template testing/def.erb:
  Filepath: /root/local/testing/templates/def.erb
  Line: 1
  Detail: No such file or directory @ rb_sysopen - /tmp/abc
 at /root/local/test2.pp:16:16 on node example.com
以下是代码(精简):

###test2.pp
klass1类{
文件{'/tmp/abc':
content=>“xxx”,
}
}
#阶段0创建文件/tmp/abc。
第0级{
包含klass1
}
#阶段1使用/tmp/abc的内容创建
#文件/tmp/def。
第1级{
文件{'/tmp/def':
内容=>模板('testing/def.erb'),
}
}
#尝试在stage1之前强制加载stage0。
包括第0阶段
类{'stage1':
require=>Class['stage0']
}
###测试/模板/def.erb
内容:

我使用的是Puppet 5.3.3。

这里的问题与包含无关,而是编译时调用
File.read(“/tmp/abc”)
时模板中的依赖关系

通常,编译发生在Puppet Master a.k.a.Puppet服务器上,此时模板函数也会运行。因此,您的模板
def.erb
试图在编译时从Puppet Master上不存在的文件中读取

更好的解决方案可能是将文件
/tmp/abc
本身的内容定义为数据或变量,然后将该变量传递给模板函数,从而完全消除对从磁盘上的文件读取的依赖

如果不完全理解为什么您一开始就试图将此文件内容分为多个类,我真的无法进一步评论

### test2.pp
class klass1 {
  file { '/tmp/abc':
    content => 'xxx',
  }
}

# Stage 0 creates the file /tmp/abc.
class stage0 {
  contain klass1
}

# Stage 1 uses the contents of /tmp/abc to create the
# file /tmp/def.
class stage1 {
  file { '/tmp/def':
    content => template('testing/def.erb'),
  }
}

# Try to force stage0 to be loaded before stage1.
include stage0
class { 'stage1':
  require => Class['stage0']
}

### testing/templates/def.erb
Contents: <%= File.read("/tmp/abc") %>