【发布时间】:2022-03-16 17:44:13
【问题描述】:
我正在使用 Chef 托管服务器、工作站和节点,并在节点上运行说明书以安装 Java、更新主机文件。我无法在站点中找到解压缩 tar 文件的参考。你能帮我在这里或直接到一些有信息的网站吗?
提前致谢。
【问题讨论】:
我正在使用 Chef 托管服务器、工作站和节点,并在节点上运行说明书以安装 Java、更新主机文件。我无法在站点中找到解压缩 tar 文件的参考。你能帮我在这里或直接到一些有信息的网站吗?
提前致谢。
【问题讨论】:
实际上,Chef 没有内置任何东西来提取 tar 文件。您有两个选择,您可以使用 execute 资源进行脱壳和解压缩,或者使用一些社区食谱,例如具有 custom resources defined for extracting tars 的 tar cookbook。
在execute 资源示例中,它可能看起来像
execute 'extract_some_tar' do
command 'tar xzvf somefile.tar.gz'
cwd '/directory/of/tar/here'
not_if { File.exists?("/file/contained/in/tar/here") }
end
而第三方 tar 食谱肯定是reads nicer
tar_package 'http://pgfoundry.org/frs/download.php/1446/pgpool-3.4.1.tar.gz' do
prefix '/usr/local'
creates '/usr/local/bin/pgpool'
end
【讨论】:
从 Chef Client 15.0 开始,内置了 archive_file 资源。它支持 tar、gzip、bzip 和 zip。
archive_file 'Precompiled.zip' do
path '/tmp/Precompiled.zip'
destination '/srv/files'
end
【讨论】:
首先需要安装包'tar',然后我们可以使用厨师的执行资源来运行tar命令。您可以使用以下 sn-p。
package 'tar'
execute "extract tar" do
command 'tar -xf #{tarPath} -C #{installPath}'
end
【讨论】:
以下厨师资源绝对可以正常工作
execute "Extract tar file" do
command "tar -xzvf #{Chef::Config['file_cache_path']}/temp.tgz -C #{Chef::Config['file_cache_path']}/temp"
action :run
end
“temp.tgz”存档文件将被提取到“temp”目录中
'#{Chef::Config['file_cache_path']}' 的路径类似于 Linux 发行版上的 /root/.chef/local-mode-cache/cache/。
【讨论】: