Search code examples
rubychef-infrachef-solo

How to check if a directory exists in a Chef recipe NOT_IF?


In a Chef recipe I've a bash resource that basically download and install a software named Revolution R. I must say that I'm really a noob in Ruby.

This is my resource:

bash 'download_revolutionr' do
    code <<-EOH
    mkdir -p /tmp/RRO-#{rro_version}
    wget https://mran.revolutionanalytics.com/install/RRO-#{rro_version}-#{rro_os_platform}-#{rro_os_version}.x86_64.deb -P /tmp/RRO-#{rro_version}
    wget https://mran.revolutionanalytics.com/install/RevoMath-#{rro_version}.tar.gz -P /tmp/RRO-#{rro_version}
    tar -xzf /tmp/RRO-#{rro_version}/RevoMath-#{rro_version}.tar.gz -C /tmp/RRO-#{rro_version}
    EOH
  not_if { ::Dir.exists?("/tmp/RR0-" + rro_version) }
end

My idea is to do not download the software if there are already on the disk inside the /tmp/RRO-version directory. So that, I added the not_if condition with the Dir.exists. But the resource is executed anyway (and a new useless copy of the software is downloaded).

Any idea of what's wrong with this?


Solution

  • I would suggest checking out out the ark cookbook for handling remote archive packages.

    include_recipe "ark"
    
    ark 'RevoMath' do
      url 'https://mran.revolutionanalytics.com/install/RevoMath-1.0.1.tar.gz'
    end
    

    Which will install the tar package content into the /usr/local/RevoMath-1.0.1 directory. These defaults can be overridden.