balanced-cookbooks / balanced-rundeck

0 stars 1 forks source link

Partial search what now? #3

Closed mjallday closed 10 years ago

mjallday commented 10 years ago

Chef::Mixin::Template::TemplateError (undefined method `partial_search' for Chef::Resource::RundeckNodeSourceFile) on line #3:

  1: <?xml version="1.0" encoding="UTF-8"?>
  2: <project>
  3:   <%- @new_resource.nodes.each do |n| -%>
  4:   <node name="<%= n['name'] %>"
  5:         description="<%= n['description'] || n['name'] %>"

  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource.rb:294:in `method_missing'
  /var/chef/cache/cookbooks/rundeck/libraries/rundeck_node_source.rb:62:in `nodes'
  (erubis):3:in `block in evaluate'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `instance_eval'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `evaluate'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/mixin/template.rb:126:in `_render_template'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/mixin/template.rb:112:in `render_template'
  /var/chef/cache/cookbooks/poise/libraries/template_content.rb:127:in `block in attribute'
  /var/chef/cache/cookbooks/poise/libraries/template_content.rb:111:in `block in attribute'
  /var/chef/cache/cookbooks/poise/libraries/template_content.rb:73:in `block in attribute'
  /var/chef/cache/cookbooks/rundeck/libraries/rundeck_node_source.rb:101:in `block in write_resources_xml'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/dsl/recipe.rb:123:in `instance_eval'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/dsl/recipe.rb:123:in `build_resource'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/dsl/recipe.rb:86:in `declare_resource'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/dsl/recipe.rb:42:in `method_missing'
  /var/chef/cache/cookbooks/rundeck/libraries/rundeck_node_source.rb:97:in `write_resources_xml'
  /var/chef/cache/cookbooks/rundeck/libraries/rundeck_node_source.rb:81:in `block (2 levels) in action_enable'
  /var/chef/cache/cookbooks/poise/libraries/subcontext_block.rb:79:in `instance_eval'
  /var/chef/cache/cookbooks/poise/libraries/subcontext_block.rb:79:in `subcontext_block'
  /var/chef/cache/cookbooks/poise/libraries/notifying_block.rb:33:in `notifying_block'
  /var/chef/cache/cookbooks/rundeck/libraries/rundeck_node_source.rb:80:in `block in action_enable'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/mixin/why_run.rb:52:in `call'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/mixin/why_run.rb:52:in `add_action'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/provider.rb:155:in `converge_by'
  /var/chef/cache/cookbooks/rundeck/libraries/rundeck_node_source.rb:79:in `action_enable'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/provider.rb:124:in `run_action'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource.rb:625:in `run_action'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/runner.rb:49:in `run_action'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/runner.rb:81:in `block (2 levels) in converge'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/runner.rb:81:in `each'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/runner.rb:81:in `block in converge'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource_collection.rb:98:in `block in execute_each_resource'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/resource_collection.rb:96:in `execute_each_resource'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/runner.rb:80:in `converge'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/client.rb:335:in `converge'
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4/lib/chef/client.rb:415:in `do_run'

@coderanger lmk if you have any ideas, i'm going to start debugging this.

mahmoudimus commented 10 years ago

@mjallday you might need 2 just add the partial-search cookbook (https://github.com/opscode-cookbooks/partial_search) in metadata

mahmoudimus commented 10 years ago

@mjallday or you might need the chef node plugin

mahmoudimus commented 10 years ago

https://github.com/oswaldlabs/chef-rundeck/pull/47 ?

mjallday commented 10 years ago

The partial search API is available in the Open Source Chef Server since 11.0.4

We're newer than that right?

mahmoudimus commented 10 years ago

yeah, but I think its most likely that we didn't include the parital_search cookbook.

mahmoudimus commented 10 years ago

try that and give it a whirl

mjallday commented 10 years ago

One step further. Code that isn't tested always has bugs. Should figure out how to test code that doesn't work on chef solo

[2014-04-07T16:51:14+00:00] ERROR: Exception handlers complete                                       
[2014-04-07T16:51:14+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out          
Chef Client failed. 88 resources updated in 140.93062393 seconds                                     
[2014-04-07T16:51:14+00:00] ERROR:                                                                   

Chef::Mixin::Template::TemplateError (undefined method `+' for nil:NilClass) on line #6:             

  4:   <node name="<%= n['name'] %>"                                                                 
  5:         description="<%= n['description'] || n['name'] %>"                                      
  6:         tags="<%= (n['roles'] + n['recipes']).join(',') %>"                                     
  7:         hostname="<%= n['fqdn'] %>"                                                             
  8:         osArch="<%= n['kernel_machine'] %>"                                                     

  (erubis):6:in `block (2 levels) in evaluate'                                                       
  (erubis):3:in `each'                                                                               
  (erubis):3:in `block in evaluate'                                                                  
  /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/erubis-2.7.0/lib/erubis/evaluator.rb:74:in `instance_ev
'                                                                                                    
mahmoudimus commented 10 years ago

ok looks like: n['roles'] and n['recipes'] are supposed to be arrays but one of them is Nil.

mahmoudimus commented 10 years ago

so what I would do is n['roles'] ||= [] and n['recipes'] ||= [] whiich says not falsy or empty list

mjallday commented 10 years ago

Will do. For the record here's what the issue is: The search query (knife search "roles:balanced-worker-integration and chef_environment:test") is returning way too many items, including a bunch of old un-bootstrapped nodes that have no roles or recipes associated with them.

This is weird because I ran knife status "roles:balanced-worker-integration as my test query and it returned a single node which is my expected result. adding the and chef_environment:test does not work as i would expect. The chef docs suggest you can run queries such as knife search node "chef_environment:QA AND platform:centos" so it's not immediately clear why this is occurring.

mjallday commented 10 years ago

Turns out that AND statement is case sensitive.

| ~/code/balanced/confucius @ mjallday-2  (confucius)(master)          
| => knife status "chef_environment:test AND roles:balanced-worker-dev"
69 hours ago, bwrk-dev-test-e4kghh-10-3-109-45, ubuntu 12.04.          
68 hours ago, bwrk-dev-test-04ypsw-10-3-108-97, ubuntu 12.04.          
67 hours ago, bwrk-dev-test-xjbx24-10-3-109-70, ubuntu 12.04.          
66 hours ago, bwrk-dev-test-6g6jat-10-3-109-143, ubuntu 12.04.         
28 minutes ago, bwrk-dev-test-limhxl-10-3-108-34, ubuntu 12.04.        

https://tickets.opscode.com/browse/CHEF-4168

mjallday commented 10 years ago

OK, this all be working now. I'm not going to fix the issue with the empty arrays since we don't have any valid nodes that have either empty roles or recipes.