简体   繁体   English

在 Puppet 中按模式在节点上的目录中查找文件

[英]Find file(s) in a directory on the node by pattern in Puppet

How can I find a file in a directory on the node by using shell-patterns or regex?如何使用 shell 模式或正则表达式在节点上的目录中找到文件?


What I want to do:我想做的事:

I download a tar file to /tmp/myfiles on the appropriate client and unpack this archive.我将 tar 文件下载到相应客户端上的/tmp/myfiles并解压缩此存档。 From it come several deb files (about 10 of them).来自它的几个 deb 文件(大约 10 个)。 The filenames change with time, because there are version numbers integrated in the name.文件名随时间变化,因为名称中集成了版本号。

The file names looks like:文件名如下所示:

  • package1_8.0-22.65.linux.x86_64.deb
  • package2_6.5-23.89.linux.x86_64.deb

I need to identify some of them (not all) to be able to install them via package with provider => dpkg .我需要识别其中一些(不是全部)才能通过packageprovider => dpkg安装它们。

The packages (like package1 , package2 ) do not occur multiple times with different version numbers, so matching could be done easily without having to compare version numbers:包(如package1package2 )不会以不同的版本号多次出现,因此无需比较版本号即可轻松完成匹配:

  • Shell pattern: package1_*.linux.x86_64.deb Shell 模式: package1_*.linux.x86_64.deb
  • Regex: ^package1_.+\.linux\.x86_64\.deb$正则表达式: ^package1_.+\.linux\.x86_64\.deb$

Is there a command or module in Puppet to find files by match pattern in a directory? Puppet 中是否有命令或模块通过匹配模式在目录中查找文件?

Or can I grab the result of exec with command => "ls /tmp/myfiles/..." and evaluate it?或者我可以使用command => "ls /tmp/myfiles/..."获取exec的结果并评估它吗?

Supposing that you mean that the tar file is downloaded as part of the catalog run, what you describe is not possible with Puppet and its standard Package resource type.假设您的意思是 tar 文件是作为目录运行的一部分下载的,那么您所描述的对于 Puppet 及其标准Package资源类型是不可能的。 Keep in mind the catalog-request cycle:请记住目录请求周期:

  1. The client gathers node facts.客户端收集节点事实。
  2. The client submits a catalog request bearing the gathered facts.客户提交包含收集到的事实的目录请求。
  3. The server uses the node's identity and facts, the manifests of the appropriate environment, and possibly the output of an external node classifier to build a catalog for the client.服务器使用节点的身份和事实、适当环境的清单以及可能的外部节点分类器的 output 为客户端构建目录。
  4. The client applies the catalog.客户应用目录。

To create Package resources during step (3), Puppet needs to know at least the names of the packages.要在步骤 (3) 中创建Package资源,Puppet 至少需要知道包的名称。 As you describe it, the names of the packages cannot be determined until step (4), which is too late.正如您所描述的,直到步骤(4)才能确定包的名称,这为时已晚。

You could have Puppet use the packages downloaded on a previous run by defining a custom fact that gathers their names from the filesystem, but that's risky and failure prone.您可以通过定义一个从文件系统收集它们的名称的自定义事实,让 Puppet 使用在之前运行时下载的包,但这是有风险且容易失败的。

I think the whole endeavor is highly suspect and likely to cause you trouble.我认为整个努力是高度可疑的,可能会给你带来麻烦。 It would probably be better to put your packages in a local repository at your site and use either node data or a metapackage or both to control which are installed.将您的包放在您站点的本地存储库中并使用节点数据或元包或两者来控制安装哪些可能会更好。 But if you insist on downloading a tar full of DEBs, then unpacking and installing them, then your best bet is probably to use an Exec for the installation.但是如果你坚持下载一个装满 DEB 的 tar,然后解压并安装它们,那么你最好的选择可能是使用Exec进行安装。 Something like this:像这样的东西:

# Ensure that the TAR file is in place
file { ${download_dir}":
  ensure => 'directory',
  # ...
}
file { "${download_dir}/packages.tar":
  ensure => 'file',
  # ...
}
-> exec { 'Install miscellaneous DEBs':
  path => ['/bin', '/usr/bin', '/sbin', /usr/sbin'],
  command => "rm '${download_dir}'/*.deb || :; tar xf '${download_dir}'/packages.tar && apt-get install '${download_dir}'/*.deb",
  provider => 'shell', 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 订阅Puppet目录中的新文件 - Subscribe to new file(s) in directory in Puppet 木偶错误:“即使在节点本地主机上也找不到任何Hiera数据文件中的数据项,并且在节点localhost上没有提供默认值” - Puppet ERROR: “Cannot find data item in any Hiera data file and no default supplied at on node localhost” even though it's right there 如何在without主文件清单文件中没有节点输入的情况下配置p客户端? - How to Configure puppet client without node entry in the puppet master's manifest file? 如何使用 Puppet 文件资源对目录授予与其文件不同的权限? - How to use a Puppet File Resource to give different permissions on a directory than to it's files? up:无法使用名称找到默认节点 - Puppet: Could not find default node by name with 木偶图书管理员,Windows和错误:无此类文件或目录 - Puppet-Librarian, windows and Error: No such file or directory puppet 3 在配置文件中添加清单目录 - puppet 3 add manifest directory in config instead file Puppet 仅当文件存在于特定目录中时才有条件 - Puppet conditional only if file exists in a particular directory 我可以在'puppet apply'运行时指定puppet的根执行目录吗? - Can I specify puppet's root execution directory at 'puppet apply' runtime? 人偶申请有时会失败,原因是:无法在确保上设置目录:文件存在-/ var / lib / puppet / facts - puppet apply sometimes fails with: Could not set 'directory on ensure: File exists - /var/lib/puppet/facts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM