Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops Puppet-依赖项检查在第一次迭代后不起作用_Loops_Dependencies_Puppet_Require - Fatal编程技术网

Loops Puppet-依赖项检查在第一次迭代后不起作用

Loops Puppet-依赖项检查在第一次迭代后不起作用,loops,dependencies,puppet,require,Loops,Dependencies,Puppet,Require,我试图使用Puppet来修改文件内容,但若文件不存在,我将跳过,什么也不做。然而,我发现依赖项检查在第一次迭代中就可以工作,但在那之后,它似乎就不起作用了。这是我的木偶清单: class tibco::hawk_gc_tuning { $domain_array = split($domain_list, '\n') $hawkgc = hiera('hawk_gc_arg','xxxxxx') $domain_array.each |$tibcodomain| { not

我试图使用Puppet来修改文件内容,但若文件不存在,我将跳过,什么也不做。然而,我发现依赖项检查在第一次迭代中就可以工作,但在那之后,它似乎就不起作用了。这是我的木偶清单:

class tibco::hawk_gc_tuning {

  $domain_array = split($domain_list, '\n')
  $hawkgc = hiera('hawk_gc_arg','xxxxxx')

  $domain_array.each |$tibcodomain| {

  notify { "Now in : ${tibcodomain} ": }

    exec {"check_presence_${tibcodomain}":
      path        => "/usr/bin:/usr/sbin:/bin",
      command     => 'true',
      onlyif      => "test -e /home/tibco/tra/domain/${tibcodomain}/hawkagent_${tibcodomain}.tra"
    }

    file_line { "change $tibcodomain hawk agent gc arg comment":
      require     => Exec["check_presence_${tibcodomain}"],
      path        => "/home/tibco/tra/domain/${tibcodomain}/hawkagent_${tibcodomain}.tra",
      line        => '# tuning for hawkagent',
      match       => '^# tuning for hawkagent',
    }->
    file_line { "change $tibcodomain hawk agent gc arg":
      path        => "/home/tibco/tra/domain/${tibcodomain}/hawkagent_${tibcodomain}.tra",
      line        => "${hawkgc}",
      match       => '^java.extended.properties=-XX\\\\:MaxPermSize\\\\=.*',
    }
  }
}
下面是我的代码的输出:

注意:现在在:A中 注意:/Stage[main]/Tibco::Hawk\u gc\u tuning/Notify[Now in:A]/message:defined'message'为'Now in:A' 注意:/Stage[main]/Tibco::Hawk\u gc\u tuning/Exec[check\u presence\u A]/returns:executed successfully 注意:现在在:B 注意:/Stage[main]/Tibco::Hawk\u gc\u tuning/Notify[Now in:B]/message:defined'message'为'Now in:B' 错误:/Stage[main]/Tibco::Hawk_gc_tuning/File_line[change B Hawk agent gc arg comment]:无法评估:没有这样的文件或目录-/home/Tibco/tra/domain/B/Hawk agent_B.tra 注意:/Stage[main]/Tibco::Hawk_gc_调优/File_行[change B Hawk agent gc arg]:依赖关系文件_行[change B Hawk agent gc arg comment]出现故障:true 警告:/Stage[main]/Tibco::Hawk_gc_调优/File_行[change B Hawk agent gc arg]:由于依赖项失败而跳过 注意:现在在:C中 注意:/Stage[main]/Tibco::Hawk\u gc\u tuning/Notify[Now in:C]/message:将“message”定义为“Now in:C” 错误:/Stage[main]/Tibco::Hawk_gc_tuning/File_line[change C Hawk agent gc arg comment]:无法计算:没有这样的文件或目录-/home/Tibco/tra/domain/C/Hawk agent_C.tra 注意:/Stage[main]/Tibco::Hawk_gc_调优/File_行[change C Hawk agent gc arg]:依赖关系文件_行[change C Hawk agent gc arg comment]出现故障:true 警告:/Stage[main]/Tibco::Hawk_gc_tuning/File_line[change C Hawk agent gc arg]:由于依赖项失败而跳过 注意:完成的目录运行时间为1.06秒


正如您在上面看到的,A、B、C都不存在,但只有第一个A给出了正确的结果并跳过了文件行资源。有人能给我一些关于这个问题的提示吗?

你的设计基于一个常见的误解

Puppet不是脚本语言。不要试图滥用
exec
资源类型来对目录中的查询建模。Puppet清单需要根据编译时出现的信息对一个一致的目标状态进行建模。如果目标状态取决于代理系统上某个文件的存在,则需要使用

特别是,您的
exec
测试无法帮助您。当文件存在时,Puppet将通过调用
true
命令尝试对其进行同步,是。这将成功。但是,如果文件不存在,Puppet会假定
exec
根本不需要同步。在这种情况下,Dependet资源就可以开始了