私は peepcode の Chef チュートリアルを進めています。テンプレート変数を使用すると、何らかの理由でエラーが発生します。例は nginx の場合です。
nginx/attributes/nginx.rb には次のものがあります。
default[:nginx][:worker_processes] = 4
nginx.conf.erb テンプレートでは、次を参照しています。
worker_processes <%= @node[:nginx][:worker_processes] %>;
以下は、chef-solo を実行すると発生するエラーです。
Template Context:
-----------------
on line #2
1: user www-data;
2: worker_processes <%= @node[:nginx][:worker_processes] %>;
3:
4: error_log /var/log/nginx/error.log;
5: pid /var/run/nginx.pid;
[2013-07-14T19:46:36+02:00] ERROR: Running exception handlers
[2013-07-14T19:46:36+02:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-07-14T19:46:36+02:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-07-14T19:46:36+02:00] FATAL: Chef::Mixin::Template::TemplateError: undefined method `[]' for nil:NilClass
エラー出力の他の部分:
Starting Chef Client, version 11.4.4
Compiling Cookbooks...
Converging 3 resources
Recipe: nginx::default
* package[nginx] action install (up to date)
* service[nginx] action enable (up to date)
* service[nginx] action start (up to date)
* template[/etc/nginx/nginx.conf] action create
================================================================================
Error executing action `create` on resource 'template[/etc/nginx/nginx.conf]'
================================================================================
Chef::Mixin::Template::TemplateError
------------------------------------
undefined method `[]' for nil:NilClass
Resource Declaration:
---------------------
# In /cookbooks/nginx/recipes/default.rb
8: template "/etc/nginx/nginx.conf" do
9: notifies :reload, "service[nginx]"
10: end
Compiled Resource:
------------------
# Declared in /cookbooks/nginx/recipes/default.rb:8:in `from_file'
template("/etc/nginx/nginx.conf") do
provider Chef::Provider::Template
action "create"
retries 0
retry_delay 2
path "/etc/nginx/nginx.conf"
backup 5
source "nginx.conf.erb"
cookbook_name :nginx
recipe_name "default"
end