Help us understand the problem. What is going on with this article?

chefでcronを設定するときの注意点

More than 5 years have passed since last update.

結論を先に書くと、「cron resourceのcommandの中身には改行をいれてはだめ」

これではまってしまう原因は、chefのreferenceに載っているexampleのせい

recipe.rb
cron "cookbooks_report" do
  action node.tags.include?('cookbooks-report') ? :create : :delete
  minute "0"
  hour "0"
  weekday "1"
  user "opscode"
  mailto "nharvey@opscode.com"
  home "/srv/opscode-community-site/shared/system"
  command %Q{
    cd /srv/opscode-community-site/current &&
    env RUBYLIB="/srv/opscode-community-site/current/lib"
    RAILS_ASSET_ID=`git rev-parse HEAD` RAILS_ENV="#{rails_env}"
    bundle exec rake cookbooks_report
  }
end

http://docs.opscode.com/resource_cron.html

あんまり深く考えずにこれだけみると、commandの値を内容をcookbooks_reportという名前のスクリプトにしてどこかに保存してくれるのかと思ってそのままつかおうとしてみたが以下のようなエラーでうまくうごかない

Chef::Exceptions::Cron: cron[crontest] (crontest::default line 98) had an error: Chef::Exceptions::Cron: Error updating state of crontest, exit: 1
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider/cron.rb:210:in `write_crontab'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider/cron.rb:140:in `block in action_create'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/why_run.rb:52:in `call'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/mixin/why_run.rb:52:in `add_action'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider.rb:149:in `converge_by'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider/cron.rb:139:in `action_create'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.8.2/lib/chef/provider.rb:114:in `run_action'
:
:

以下によるとcommandの中に改行をいれてはだめらしい。

http://stackoverflow.com/questions/16662065/chef-cant-create-cron

改行をなくせば回避できる

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away