[英]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
.我需要识别其中一些(不是全部)才能通过
package
和provider => 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:包(如
package1
, package2
)不会以不同的版本号多次出现,因此无需比较版本号即可轻松完成匹配:
package1_*.linux.x86_64.deb
package1_*.linux.x86_64.deb
^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:请记住目录请求周期:
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.