3

您将如何使用 puppet 更改名称不一致的文件的权限?

我的任务是管理一个在其末尾附加日期的二进制文件,如下所示:

lrwxrwxrwx 1 root root       18 Oct 25 18:46 apbridge -> ./apbridge20131025
lrwxrwxrwx 1 root root       18 Oct 25 18:46 apbridge1025 -> ./apbridge20131025
-rwxr-xr-x 1 root root     2914 Oct 25 18:46 apbridge20131025

apbridge20131025 的权限错误。通常以下内容会改变它:

  file  {'/root/alpsSim/alps_simulator_r7537/tester/apbridge20131025':
    owner   =>  'root',
    group   =>  'root',
    ensure  =>  file,
    mode    => '0755',
  }

但是,因为我无法预测 apbridge 将以什么数字结束,所以这很可能会中断。

我无法控制 apbridgexxxxx 的名称,因为它是由第 3 方脚本安装的。最后的数字代表它安装的日期。

有没有办法在人偶文件资源声明中使用通配符?

4

2 回答 2

3

我建议你使用 exec:

exec { 'apbridge':
  command => 'find /root/alpsSim/alps_simulator_r7537/tester/ -maxdepth 1 -type f -iname "apbridge*" -exec chmod 755 {} \;',
  path    => '/bin:/sbin:/usr/bin:/usr/sbin',
}
于 2013-10-27T14:29:46.423 回答
1

通常我建议不要exec在 Puppet 中使用,但在这种情况下,chmod它是幂等的——无论你如何运行它,你都会得到相同的结果。Puppet 也有一点好处,它不必为尝试更改权限的每个文件计算 md5 哈希值。

也就是说,确保权限的一种更优雅的方法是在包含文件的目录上递归地设置它们——假设只有apbridge*文件存在。

file  {'/root/alpsSim/alps_simulator_r7537/tester':
    owner   =>  'root',
    group   =>  'root',
    ensure  =>  directory,
    recurse => true,
    mode    => '0755',
}
于 2013-10-29T02:12:08.413 回答