Skip particular resource from execution

suppose we have written a resource to untar a .tar file .

how can we skip the execution of that resource if that tar has already been unzipped.

You could use guards
For example:

not_if { ::File.exist?('/your/tar/file') }

the tar file that would be unzipped will give many folders on specific location,

and the tar is first being copied then its being unzipped. so we cannot apply this condition. is there any other way

If the simple file check with guard is not enough, then you could try the following cookbook

If you have multiple locations, you can also do multiple guard interpreters

not_if { ::File.exist?('/foo/') }
not_if { ::File.exist?('/bar/') }

If your tar has a metadata or some other text file that is unique pre version, you could check that.

For example, say your tar has a build.txt file in it


build: 2017-10-29

Then you could read the file and compare versions, only untarting if the version doesn’t match

exec 'untar' do
  command 'tar -xvf /tmp/foo.tgz -C /foo'
  not_if { ::File.readlines('/foo/build.txt').grep('2017-10-29').empty?) }

Or if there is some other programatic way like fetching from an API, you could use ruby blocks and notifiers

   exec 'untar' do
      command 'tar -xvf /tmp/foo.tgz -C /foo'
      action :nothing

  ruby_block 'check_version' do
      # Some ruby code to check version
    notifies :run 'exec[untar], :immedietly