【问题标题】:How to unzip tar.Z file through CHEF cookbooks如何通过 CHEF 食谱解压缩 tar.Z 文件
【发布时间】:2022-03-16 17:44:13
【问题描述】:

我正在使用 Chef 托管服务器、工作站和节点,并在节点上运行说明书以安装 Java、更新主机文件。我无法在站点中找到解压缩 tar 文件的参考。你能帮我在这里或直接到一些有信息的网站吗?

提前致谢。

【问题讨论】:

    标签: chef-infra chef-recipe


    【解决方案1】:

    实际上,Chef 没有内置任何东西来提取 tar 文件。您有两个选择,您可以使用 execute 资源进行脱壳和解压缩,或者使用一些社区食谱,例如具有 custom resources defined for extracting tarstar 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
    

    【讨论】:

    • 焦油食谱不再积极开发。而且我无法让它与本地提取一起使用,因此执行 tar 命令的变体对我有用。有替代的食谱(如tarball-chef-cookbook,但这不是超市的一部分,也不支持自定义焦油参数。
    【解决方案2】:

    从 Chef Client 15.0 开始,内置了 archive_file 资源。它支持 tar、gzip、bzip 和 zip。

    archive_file 'Precompiled.zip' do
      path '/tmp/Precompiled.zip'
      destination '/srv/files'
    end
    

    【讨论】:

      【解决方案3】:

      首先需要安装包'tar',然后我们可以使用厨师的执行资源来运行tar命令。您可以使用以下 sn-p。

      package 'tar'
      execute "extract tar" do
       command 'tar -xf #{tarPath} -C #{installPath}'
      end 
      

      【讨论】:

        【解决方案4】:

        以下厨师资源绝对可以正常工作

        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/。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-02-01
          • 2014-11-06
          • 1970-01-01
          • 2012-09-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多