oswaldlabs / chef-rundeck

Integrates Chef with RunDeck, we are referring users to https://github.com/atheiman/better-chef-rundeck as this repository is inactive at this time.
Apache License 2.0
97 stars 85 forks source link

Missing node information - Fixed #42

Closed ColOfAbRiX closed 10 years ago

ColOfAbRiX commented 10 years ago

Hi, I have encountered a problem with chef-rundeck, the error is:

NoMethodError - undefined method []' for nil:NilClass: /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-rundeck-1.0.1/lib/chef-rundeck.rb:62:inblock (2 levels) in class:ChefRundeck' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-rundeck-1.0.1/lib/chef-rundeck.rb:57:in each' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-rundeck-1.0.1/lib/chef-rundeck.rb:57:inblock in class:ChefRundeck'

My Chef-rundeck is running on the client as I will move it to the server when I have fully tested it. I am using SuSE Linux 11 SP3, Ruby 1.9.3 on both server and client, on the server is installed chef-server 11.0.8-1 and chef 11.6.0 and on the client chef 11.8.4

I debugged the file chef-rundeck-1.0.1/lib/chef-rundeck.rb and, referencing these lines:

rest = Chef::REST.new(ChefRundeck.api_url, ChefRundeck.username, ChefRundeck.client_key)
nodes = rest.get_rest("/nodes/")
nodes.keys.each do |node_name|
  node = rest.get_rest("/nodes/#{node_name}")

at some point, the variable node doesn't contain the expected values. It's like it is not set for one of my nodes.

I think the script should check for all the values he uses before writing the output, so After the line

    node = rest.get_rest("/nodes/#{node_name}")

I added these lines:

  # Sometimes node information are missing. I check that all the required keys are present, otherwise I skip
  key_check = [ "kernel", "fqdn", "platform", "platform_version", "tags" ]
  if (node.keys & key_check).count != key_check.count then next end

I hope this helps!

bscott commented 10 years ago

@ColOfAbRiX Thx

ColOfAbRiX commented 10 years ago

I have spotted the real problem.

I have edited some nodes using knife node from file and, after that operation, the node attributes are missing with no real reason. So, I think, it is an issue of Chef.

Solution/ideas?

Thanks.

This is a sample JSON file I use to configure my nodes:

{
    "name" : "vmcolofabrix",
    "json_class" : "Chef::Node",
    "chef_type" : "node",
    "chef_environment" : "personal",
    "normal" : {
        "tags" : [
            "ColOfAbRIX"
        ]
    },
    "automatic" : {},
    "default" : {},
    "override" : {},
    "run_list" : [
        "role[common]"
    ]
}
leftathome commented 10 years ago

I know this one's a bit of an oldie so this probably isn't of interest anymore, but questions deserve answers in the age of search engines.

In principle our validation code should be catching this sort of thing these days, but looking at your node object it appears to be missing several values that matter to chef-rundeck, such as platform, platform_family and kernel.