Adhitya Ganesan
Adhitya Ganesan

Reputation: 27

tar -C fails in Chef

I'm trying to decompress a tar file with this code in my chef recipe :

execute "#{node['ffmpeg']['yasm']}.tar.gz" do
      command "tar -xzvf /tmp/#{node['ffmpeg']['yasm']}.tar.gz -C #{node['ffmpeg']['source_files']}"

But the next command fails saying that there's no such file in the specified directory. What's going on? What do I do? The file and the directory exist Thanks

Upvotes: 0

Views: 107

Answers (2)

Adhitya Ganesan
Adhitya Ganesan

Reputation: 27

For anyone else who might have struggled like me, the solution I arrived at was

bash "extract-yasm" do
  cwd path/to/destination
  code <<-EOH
  tar -xzvf /tmp/file-name.tar.gz
  EOH
end

Thanks everyone for all the help :)

Upvotes: 1

gsone
gsone

Reputation: 1231

You need to be sure that /tmp/#{node['ffmpeg']['yasm']}.tar.gz exists and change directory -C also exists.

Before execute you can put:

   directory node['ffmpeg']['source_files'] do
     recursive true
   end

in order to create change dir if its missing.

In order to check if file exists /tmp/#{node['ffmpeg']['yasm']}.tar.gz you can add

  only_if { ::File.exist?("/tmp/#{node['ffmpeg']['yasm']}.tar.gz") }

to your execute resource.

In that case your code will be protected by the errors.

One more thing - if you need to create change directory only if execute resource is triggered you need to use notify resource.

Upvotes: 2

Related Questions