title: How to tell Chef to take an action if the desired package to install doesn't exist?
body: <p>I'm trying to get Chef to perform the following:</p>
  
  <ul>
  <li>Check if the desired debian (can be any package really) is available</li>
  <li>If it is, apt-get install the package</li>
  <li>If it's not, build the package using the source</li>
  </ul>
  
  <p>I know you can do:</p>
  
  <pre class="lang-rb prettyprint-override"><code>remote_file "some remote file" do
    ...
    not_if "apt-cache search 'mypackage'"
  end
  </code></pre>
  
  <p>However, I tried:</p>
  
  <pre class="lang-rb prettyprint-override"><code>ruby_block "Attempting to install #{node[:bact][:application_name]}" do
    block do
      cmd = Chef::ShellOut.new("apt-get install -y --force-yes #{node[:bact][:application_name]}")
      exec_result = cmd.run_command
      if exec_result.exitstatus != 0
        Chef::Log.info 'Go grab some coffee, this might be a while....'
        resources("execute[install-#{node[:bact][:application_name]}-via-pip]").run_action(:run)
      end
    end
    action :create
  end
  </code></pre>
  
  <p>Is there an easier and less uglier way to do this?</p>
  
  <p>Basically, what I'd ideally like to do is:</p>
  
  <pre class="lang-rb prettyprint-override"><code>begin
     package 'some-package-name' do
       action :install
     done
  rescue Chef::Exception
     # Do something here
  end
  </code></pre>