Search code examples
chef-infracookbookrecipe

How to check and install cron using chef


All,

I want to check if cron is installed on a server using chef. If it is not installed it should be installed using chef.

I have written something like this :

 yum_package 'cron' do
       action :install
      end

It is installing cron. How can I verify before installing.


Solution

  • You don't need to verify anything. Chef is clever enough to know that it shouldn't install a package if it's already there.

    From: https://docs.chef.io/resource_examples.html

    Get the package from a remote location, but only if the package does not already exist on the target system

    If you want to make sure a particular version is installed, you can specify that. Details here: https://docs.chef.io/resource_yum.html