berkshelf / ridley

A reliable Chef API client with a clean syntax
Other
231 stars 85 forks source link

Ec2? method does not return true for ec2 instances #359

Closed howdoicomputer closed 7 years ago

howdoicomputer commented 7 years ago
ridley.node.all.each do |node|
  puts node.ec2?
  sleep 5
end

Just simple code to test it out. All the instances registered to my Chef server have an instance id as a node name and an ec2 attribute structure but fail to register as cloud nodes via Ridley.

Also, .public_hostname and .public_ipaddress return nil on every node object.

howdoicomputer commented 7 years ago

Now, I can get around this by doing a partial_search like so

nodes = ridley.partial_search(:node, 'name:*', ['ec2'])
puts nodes.count
puts ridley.node.all.count

nodes.each do |node|
  puts node.automatic.ec2.public_hostname
  sleep 5
end
⋊> ~/w/w/chef_ec2_dossier ruby test.rb                                                                         22:38:14
1000
13188
ec2-54-87-46-137.compute-1.amazonaws.com

However, partial search has a page limit of 1000? A full search caused Ridley to crash. Not surprising given the obscene node count (I just came into a role where the Chef environment was extremely neglected).

It also looks like the .automatic method doesn't return values when taken from a node collection?

ridley.node.all.each do |node|
  puts node.automatic.to_hash
  sleep 5
end

Returns an empty hash for each node.

howdoicomputer commented 7 years ago

Oh, duh. Found it in your README.md.

Notify: You have to send the #reload message to node objects returned from a full listing. Their attributes aren't automatically populated from the initial search.

Herp a derp derp. Now everything works.

For anyone searching through issues to find out why your code doesn't work. Well, here it is.

Also, to grab node attributes: .default .automatic .blah. Totally forgot I had to do a reload from last time I touched this library. Hah.