Search code examples
chef-infra

How do I create a cron job via a chef receipe using the cron resource?


I have the following in the cron.rb file.

cookbook 'cron', '~> 7.0.4', :supermarket

cron 'Check-In to Chef Manage' do
   minute '*/2'
   command 'chef-client'
 end

I've verified that the recipe is on the node, via Chef Manage, and yet it doesn't run on the node.

I don't understand if anything else needs to be configured.


Solution

  • The first line is not needed. Leaving the recipe (i.e. cron.rb) as:

    cron 'Check-In to Chef Manage' do
       minute '*/2'
       command 'chef-client'
     end
    

    Second, cron.rb must be called in the default.rb file; i.e. include_recipe "<cookbook nam>::cron"