Puppet:一个 exec 块创建了多少次 运行?

Puppet: how many times an exec block with creates run?

我有以下两个 exec 资源,并且希望 exec 资源 run the script 到 运行 只要文件 /var/lib/my-file 不存在。我想知道如果文件永远不会被创建会发生什么。 exec 资源 check if file exists 运行 会一直循环直到它被创建吗?

exec { 'run the script':
  command     => "python my-script.py",
  path        => '/bin:/usr/bin:/usr/local/bin',
  timeout     => 900,
  subscribe   => File["my-settings.yaml"],
  refreshonly => true,
} 

exec { 'check if file exists':
  command => 'true',
  path    => '/bin:/usr/bin:/usr/local/bin',
  creates => '/var/lib/my-file',
  notify  => Exec['run the script']
}

每个目录应用程序仅应用一次资源,每个节点的每个目录编译发生一次。您可以通过尝试自己验证这一点。

如果Python 脚本创建文件失败,资源将在下一个目录应用程序中再次应用。否则,幂等性优先,资源不被应用,因为文件已经存在。

此外,您应该将资源简化为:

exec { 'run the script':
  command     => 'python my-script.py',
  path        => '/bin:/usr/bin:/usr/local/bin',
  timeout     => 900,
  creates     => '/var/lib/my-file',
  subscribe   => File["my-settings.yaml"],
  refreshonly => true,
}

这在功能上与您在问题中的相同,并且更高效且更易于阅读。