人偶错误:文件 [...] 似乎不在目录中

Error in puppet : File[...] doesn't seem to be in the catalog

我想通过 puppet 添加连续的 crons,第一个设置为每 10 分钟一次,第二个设置为周日 运行 7:00PM。

puppet 中的第一个 cron 工作正常,但第二个显示以下错误: “错误:无法从远程服务器检索目录:服务器上的错误 400:无效关系:Cron[notifyinactivetargetweekly] { require => File[...weeklynotifyinactivejob.sh] },因为 File[...weeklynotifyinactivejob.sh] 目录里好像没有 警告:不在失败的目录上使用缓存 错误:无法检索目录;跳过 运行"

下面是清单代码。

cron { 'firstcron':
    command => "${scmphptpl::DocRootDir}/firstcron.sh ${scmphptpl::Environment} ${scmphptpl::DocRootDir}",
    require => File["${scmdemophp::DocRootDir}/firstcron.sh"],
    minute  => '*/10',
    environment=>["COMPOSER_HOME=${scmphptpl::DocRootDir}",
                    "SYMFONY_ENV=${scmphptpl::Environment}",
                    "SYMFONY_DEBUG=${scmphptpl::Debug}",
                    "PATH=/opt/rh/php55/root/usr/bin:/opt/rh/php55/root/usr/sbin:/usr/local/sbin:/usr/local/bin:/sbin/:/bin/:/usr/sbin/:/usr/bin/"
                ],

}->
cron { 'weeklynotifyinactivejob':
    command => "${scmphptpl::DocRootDir}/weeklynotifyinactivejob.sh ${scmphptpl::Environment} ${scmphptpl::DocRootDir}",
    require => File["${scmphptpl::DocRootDir}/weeklynotifyinactivejob.sh"],
    minute  => '00',
    hour  => '19',
    weekday  => 'Sunday',
    environment=>["COMPOSER_HOME=${scmphptpl::DocRootDir}",
                    "SYMFONY_ENV=${scmphptpl::Environment}",
                    "SYMFONY_DEBUG=${scmphptpl::Debug}",
                    "PATH=/opt/rh/php55/root/usr/bin:/opt/rh/php55/root/usr/sbin:/usr/local/sbin:/usr/local/bin:/sbin/:/bin/:/usr/sbin/:/usr/bin/"
                ],

}->

hieradata 包含以下类加载:

classes:
  - scmphptpl::myprojectdeploy

myprojectdeploy 的 init.pp 包括:

class scmphptpl {
    $DocRootDir = "/app/code"

我检查了文件“/app/code/weeklynotifyinactivejob.sh”是否存在。

更新:

我已经创建了相同的,但由于某些原因,cron 没有按照时间 运行ning:

file { "${DocRootDir}/weeklynotifyinactivejob.sh":
  ensure  => file,
  content => "... whatever's in the file, or use a template/source ...",
}->
cron { 'notifyinactivetargetweekly':
    command => "${scmphptpl::DocRootDir}/weeklynotifyinactivejob.sh ${scmphptpl::Environment} ${scmphptpl::DocRootDir}",
    require => File["${scmdemophp::DocRootDir}/weeklynotifyinactivejob.sh"],
    minute  => '*/15',
    environment=>["COMPOSER_HOME=${scmphptpl::DocRootDir}",
                    "SYMFONY_ENV=${scmphptpl::Environment}",
                    "SYMFONY_DEBUG=${scmphptpl::Debug}",
                    "PATH=/opt/rh/php55/root/usr/bin:/opt/rh/php55/root/usr/sbin:/usr/local/sbin:/usr/local/bin:/sbin/:/bin/:/usr/sbin/:/usr/bin/"
                ],

}

但它在 15 分钟后 运行 不可用,需要帮助

  1. 木偶日志说: 文件[/app/code/edlconsole/firstcron.sh]/模式:模式将“0664”更改为“0751”
  2. 但它没有显示相同的 文件[/app/code/edlconsole/weeklynotifyinactivejob.sh]/模式:模式将“0664”更改为“0751”
  3. 虽然反映了频率变化

使用 requirebeforesubscribenotify 参数表示资源与文件相关或其他资源必须包含有效引用。

您正在使用的 require 参数需要在您的 Puppet 清单中定义的特定文件 resource,不一定是服务器本身上的文件。这就是文件不在目录 中的意思 (目录是根据清单构建的)。

require => File["${scmdemophp::DocRootDir}/notifyinactivetargetweekly.sh"],

这意味着您的清单中必须定义一个名为 /app/code/notifyinactivetargetweekly.sh 的文件资源,例如在 scmdemophp class 你可以有:

file { "${DocRootDir}/notifyinactivetargetweekly.sh":
  ensure  => file,
  content => "... whatever's in the file, or use a template/source ...",
}

然后require依赖就可以解决了

如果您不想使用 Puppet 管理文件,则只需将 require 参数省略即可。