【问题标题】:How to tell chef to not untar a tarball if it has already been extracted?如果已经提取了压缩包,如何告诉厨师不要解压压缩包?
【发布时间】:2020-08-13 13:40:04
【问题描述】:

在我的主厨代码中,我正在使用“执行”资源“解压特定目录中的 tarball。如何编写代码以便仅在 tarball 中的文件并非全部存在于目录?换句话说,如果 tarball 已经解压,则不要执行任何操作。

这是我目前所拥有的:

execute 'unpack' do 
  command "unzip #{working_dir}/config.zip -d #{working_dir}"
  not_if # not if the files and directories within config.zip are already within "working_dir"

结束

【问题讨论】:

    标签: bash chef-infra


    【解决方案1】:

    在 Chef 客户端 15 及更高版本中,可以使用 archive_file resource。示例:

    archive_file "#{working_dir}/config.zip" do
      destination working_dir
      overwrite false          # Default behaviour
      action :extract
    end
    

    【讨论】:

      【解决方案2】:

      这里的一种典型方法(假设您的 config.zip 的管理方式使其时间戳真正反映推出新版本的时间点)是维护成功标记,并检查该标记是否比config.zip 更新:

      execute 'unpack' do 
        command "unzip #{working_dir}/config.zip -d #{working_dir} && touch #{working_dir}/.unpack"
        not_if "test #{working_dir}/.unpack -nt #{working_dir}/config.zip"
      

      【讨论】:

        【解决方案3】:
        execute "#{working_dir}/config.zip" do
            command "unzip #{working_dir}/config.zip -d #{working_dir}"
            not_if do
              ::File.exist?("#{working_dir}/somefile")
            end
          end
        

        我同意Seshadri C 使用archive_file 资源

        https://docs.chef.io/resources/archive_file/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-12-21
          • 2016-04-22
          • 2012-03-17
          • 1970-01-01
          • 2018-06-25
          • 1970-01-01
          • 2010-10-15
          • 1970-01-01
          相关资源
          最近更新 更多