【问题标题】:Puppet trigger resource only if other resource applied a change?仅当其他资源应用更改时木偶触发资源?
【发布时间】:2017-08-28 12:07:55
【问题描述】:

我有一个像这样的pp 清单:

vcsrepo { '/home/pi/pop_machine':
  ensure   => latest,
  provider => git,
  source   => 'https://github.com/kirkins/pop-machine-demo.git',
  revision => 'master',
}

exec { 'npm start':
  command => "/usr/bin/killall electron & /usr/bin/npm start",
  cwd     => "/home/pi/pop_machine/",
}

我希望 exec 资源仅在 vcsrepo 资源在 github 上找到更新并进行更改时重新启动设备应用程序。

单独使用 puppet 是否可行,或者我应该编写一个 bash 脚本来检查上次更新 .git 文件夹的时间?

【问题讨论】:

    标签: puppet


    【解决方案1】:

    您可以将元参数 subscribe 和参数 refreshonly 与您的 exec 资源一起使用来完成此操作。

    首先,使用subscribe 元参数在vcsrepo 上建立exec 的排序关系,并检查资源更改:https://docs.puppet.com/puppet/latest/metaparameter.html#subscribe

    接下来,使用refreshonly 指示exec 资源仅在vcsrepo 存储库影响更改时应用更改(相对于非幂等):https://docs.puppet.com/puppet/latest/types/exec.html#exec-attribute-refreshonly

    看起来像:

    vcsrepo { '/home/pi/pop_machine':
      ensure   => latest,
      provider => git,
      source   => 'https://github.com/kirkins/pop-machine-demo.git',
      revision => 'master',
    }
    
    exec { 'npm start':
      command     => "/usr/bin/killall electron & /usr/bin/npm start",
      cwd         => "/home/pi/pop_machine/",
      subscribe   => Vcsrepo['/home/pi/pop_machine'],
      refreshonly => true,
    }
    

    【讨论】:

      【解决方案2】:

      Matt Schuchard's 答案对我不起作用。由于“exec”中的“subscribe”,我不断收到 puppet 的错误:

      Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Could not autoload puppet/type/vcsrepo: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/vcsrepo'.
      

      但这确实对我有用:

      vcsrepo { '/home/pi/pop_machine':
        ensure   => latest,
        provider => git,
        source   => 'https://github.com/kirkins/pop-machine-demo.git',
        revision => 'master',
        notify   => Exec['npm start'],
      }
      
      exec { 'npm start':
        command     => "/usr/bin/killall electron & /usr/bin/npm start",
        cwd         => "/home/pi/pop_machine/",
        refreshonly => true,
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-18
        • 1970-01-01
        • 2022-10-19
        • 1970-01-01
        • 2015-07-13
        • 1970-01-01
        • 2017-03-17
        • 1970-01-01
        相关资源
        最近更新 更多