2015-12-30 4 views
0

httpd Использование поваренной книги я пытаюсь передать переменную к лежащей в основе template ресурса через variables параметра атрибута httpd_config. Это приводит к фатальной ошибке. Что мне здесь не хватает?Использование «httpd_config» результаты ресурса «HTTPd» Повар поваренной книги по ошибке в «неопределенной локальной переменной или метода»

Я использую:

  • Ubuntu 14,04 (система будет предоставлен)
  • Chef Development Kit 0.10.0
  • шеф-клиент 12.5.1
  • HTTPD Cookbook 0.3.3

Документация:

https://supermarket.chef.io/cookbooks/httpd#httpd_config

Рецепт:

node['solid_projects']['projects'].each do |project| 

    httpd_service project.name do 
     mpm 'prefork' 
     action [:create] 
    end 

    httpd_config project.name do 
    instance project.name 
    source 'site.conf.erb' 
    notifies :restart, "httpd_service[#{project.name}]" 
    variables :project => project 
    end 

end 

site.conf.erb:

<VirtualHost *:80> 
    ServerName <%= project.fqdn %> 
    DocumentRoot "/var/www/<%= project.name %>/public_html" 
    <Directory /> 
    Options FollowSymLinks 
    AllowOverride None 
    </Directory> 
    <Directory "/var/www/<%= project.name %>/public_html" > 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride None 
    Order allow,deny 
    allow from all 
    </Directory> 
</VirtualHost> 

Сообщение об ошибке:

* httpd_config_debian[everest] action create 
    * directory[/etc/apache2-everest/conf-available] action create (up to date) 
    * template[/etc/apache2-everest/conf-available/everest.conf] action create 

     ================================================================================ 
     Error executing action `create` on resource 'template[/etc/apache2-everest/conf-available/everest.conf]' 
     ================================================================================ 

     Chef::Mixin::Template::TemplateError 
     ------------------------------------ 
     undefined local variable or method `project' for #<Chef::Mixin::Template::TemplateContext:0x000000037d1e48> 

     Cookbook Trace: 
     --------------- 
     /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:119:in `compile_and_converge_action' 

     Resource Declaration: 
     --------------------- 
     # In /var/chef/cache/cookbooks/httpd/libraries/httpd_config_debian.rb 

     34:   template "/etc/#{apache_name}/conf-available/#{config_name}.conf" do 
     35:   owner 'root' 
     36:   group 'root' 
     37:   mode '0644' 
     38:   variables(new_resource.variables) 
     39:   source new_resource.source 
     40:   cookbook new_resource.cookbook 
     41:   action :create 
     42:   end 
     43: 

     Compiled Resource: 
     ------------------ 
     # Declared in /var/chef/cache/cookbooks/httpd/libraries/httpd_config_debian.rb:34:in `block in <class:HttpdConfigDebian>' 

     template("/etc/apache2-everest/conf-available/everest.conf") do 
     action [:create] 
     retries 0 
     retry_delay 2 
     default_guard_interpreter :default 
     path "/etc/apache2-everest/conf-available/everest.conf" 
     backup 5 
     atomic_update true 
     source "site.conf.erb" 
     variables {"project"=>{"name"=>"everest", "use_stages"=>true}} 
     declared_type :template 
     cookbook_name "solid_webserver" 
     owner "root" 
     group "root" 
     mode "0644" 
     end 

     Template Context: 
     ----------------- 
     on line #2 
     1: <VirtualHost *:80> 
     2: ServerName <%= project.fqdn %> 
     3: DocumentRoot "/var/www/<%= project.name %>/public_html" 
     4: <Directory /> 
     5:  Options FollowSymLinks 


    ================================================================================ 
    Error executing action `create` on resource 'httpd_config_debian[everest]' 
    ================================================================================ 

    Chef::Mixin::Template::TemplateError 
    ------------------------------------ 
    undefined local variable or method `project' for #<Chef::Mixin::Template::TemplateContext:0x000000037d1e48> 

    Cookbook Trace: 
    --------------- 
    /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:119:in `compile_and_converge_action' 

    Resource Declaration: 
    --------------------- 
    # In /var/chef/cache/cookbooks/solid_webserver/recipes/httpd.rb 

    10: httpd_config project.name do 
    11:  instance project.name 
    12:  source 'site.conf.erb' 
    13:  notifies :restart, "httpd_service[#{project.name}]" 
    14:  variables 'project' => project 
    15: end 
    16: 

    Compiled Resource: 
    ------------------ 
    # Declared in /var/chef/cache/cookbooks/solid_webserver/recipes/httpd.rb:10:in `block in from_file' 

    httpd_config_debian("everest") do 
     action [:create] 
     retries 0 
     retry_delay 2 
     default_guard_interpreter :default 
     declared_type :httpd_config 
     cookbook_name "solid_webserver" 
     recipe_name "httpd" 
     instance "everest" 
     source "site.conf.erb" 
     variables {"project"=>{"name"=>"everest", "use_stages"=>true}} 
     httpd_version "2.4" 
     config_name "everest" 
    end 

    Template Context: 
    ----------------- 
    on line #2 
     1: <VirtualHost *:80> 
     2: ServerName <%= project.fqdn %> 
     3: DocumentRoot "/var/www/<%= project.name %>/public_html" 
     4: <Directory /> 
     5:  Options FollowSymLinks 

Recipe: firewall::default 
    * firewall[default] action restart 
    * file[/etc/default/ufw-chef.rules] action create (up to date) 
    (up to date) 

Running handlers: 
[2015-12-30T18:41:13+01:00] ERROR: Running exception handlers 
Running handlers complete 
[2015-12-30T18:41:13+01:00] ERROR: Exception handlers complete 
Chef Client failed. 3 resources updated in 16 seconds 
[2015-12-30T18:41:15+01:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out 
[2015-12-30T18:41:15+01:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report 
[2015-12-30T18:41:15+01:00] ERROR: 

Chef::Mixin::Template::TemplateError (undefined local variable or method `project' for #<Chef::Mixin::Template::TemplateContext:0x000000037d1e48>) on line #2: 

    1: <VirtualHost *:80> 
    2: ServerName <%= project.fqdn %> 
    3: DocumentRoot "/var/www/<%= project.name %>/public_html" 
    4: <Directory /> 
    5:  Options FollowSymLinks 

    (erubis):2:in `block in evaluate' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `instance_eval' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `evaluate' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/mixin/template.rb:162:in `_render_template' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/mixin/template.rb:148:in `render_template' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/provider/template/content.rb:53:in `file_for_provider' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/file_content_management/content_base.rb:40:in `tempfile' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/provider/file.rb:462:in `tempfile' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/provider/file.rb:339:in `do_generate_content' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/provider/file.rb:150:in `action_create' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/provider.rb:144:in `run_action' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource.rb:596:in `run_action' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:74:in `run_action' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:106:in `block (2 levels) in converge' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:106:in `each' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:106:in `block in converge' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/resource_list.rb:83:in `block in execute_each_resource' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:116:in `call' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:85:in `step' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/resource_list.rb:81:in `execute_each_resource' 
    /opt/chef/embedded/lib/ruby/2.1.0/forwardable.rb:183:in `execute_each_resource' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:105:in `converge' 
    /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:119:in `compile_and_converge_action' 
    (eval):2:in `action_create' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/provider.rb:144:in `run_action' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource.rb:596:in `run_action' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:74:in `run_action' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:106:in `block (2 levels) in converge' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:106:in `each' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:106:in `block in converge' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/resource_list.rb:83:in `block in execute_each_resource' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:116:in `call' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:85:in `step' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/resource_collection/resource_list.rb:81:in `execute_each_resource' 
    /opt/chef/embedded/lib/ruby/2.1.0/forwardable.rb:183:in `execute_each_resource' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/runner.rb:105:in `converge' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/client.rb:658:in `block in converge' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/client.rb:653:in `catch' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/client.rb:653:in `converge' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/client.rb:692:in `converge_and_save' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/client.rb:271:in `run' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application.rb:261:in `block in fork_chef_client' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application.rb:249:in `fork' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application.rb:249:in `fork_chef_client' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application.rb:215:in `block in run_chef_client' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/local_mode.rb:44:in `with_server_connectivity' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application.rb:203:in `run_chef_client' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application/client.rb:413:in `block in interval_run_chef_client' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application/client.rb:403:in `loop' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application/client.rb:403:in `interval_run_chef_client' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application/client.rb:393:in `run_application' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/lib/chef/application.rb:58:in `run' 
    /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.6.0/bin/chef-client:26:in `<top (required)>' 
    /usr/bin/chef-client:54:in `load' 
    /usr/bin/chef-client:54:in `<main>' 


[2015-12-30T18:41:15+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) 

ответ

2

Это должно быть <%= @project['name'] %> (а также для полного доменного имени).