UNIX diff 命令在 puppet exec 上的使用

UNIX diff command usuage on puppet exec

我有 2 个 Release.ini 文件:

我想验证下载的文件(即/CodeRootFolder/tmp/Release.ini)是否有变化,如果有变化则通过 puppet exec 执行 rsync 命令,如下所示。

错误是如果有变化,它不执行,好像是 diff returns 1.

exec {'Actual code deployment with rsync':
    command => "rsync ${myclass::CodeRootFolder}/tmp/* ${myclass::DocRootDir}/)",
    #cwd => "${myclass::CodeRootFolder}",
    onlyif => "diff --changed-group-format='%<' --unchanged-group-format='' ${myclass::CodeRootFolder}/tmp/Release.ini ${myclass::DocRootDir}/Release.ini",
    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/'], 
}

我的问题有好的解决办法吗

提前致谢

The error is if there change, it does not executing, it seems to as diff returns 1.

是的,没错。

Invoking diff

An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.

如果你想在有变化时执行命令,你必须使用unless而不是onlyif