hw-cookbooks/discovery

NameError: Cannot find a resource for host on ubuntu version 12.04

Closed this issue · 11 comments

When using the Discovery library on Ubuntu 12.04, I get the following error:

NameError: Cannot find a resource for host on ubuntu version 12.04

I am using the Discovery.ipaddress(..) example from the main page with :type => public

Discovery.ipaddress(:remote_node => host, :node => node, :type => :public)

However if I change the value of 'host' to 'node' then it works. Someone in #chef mentioned that it may be a problem with ruby 1.8.7 which is running on my server.

I also unfortunately don't understand the purpose of :remote_node and what valid values should look like, so it might just be a documentation/misunderstanding on my part.

Thanks!

The exception you mention is simply telling you that you are using a local which doesn't exist, unfortunately the recipe DSL snaps it up.

You want something like this:

host = discovery_search("rabbitmq", :empty_ok => false)
ipaddress = discovery_ipaddress(:remote_node => host)

Sorry, could you elaborate please? I'm looking at some of the code and the examples, and I don't quite follow. I appreciate the quick response.

I just noticed actually that the readme.md contains:

host = Discovery.search(...)

Perhaps I'm just not quite understanding exactly what :remote_node is suppose to contain? It's purpose isn't immediately clear to me.

OK I might be starting to somewhat understand what is going on here. Seems like if :remote_node isn't passed it could potentially just assume to use 'node', but I defer to those smarter than I :)

This is what I did to get my search and ipaddress stuff working. The purpose was to return the local nodes external IP address in a way that works across EC2 and non-EC2 servers with Chef clients that both do and don't contain the cloud attribute (without having to express the same logic in multiple places). I guess alternatively I could have used my own library, but this seems to also allow me to do a search for a node, and return it's external IP address (not just my own).

host = Discovery.search("provisioning_server", :node => node, :return_self => true, :empty_ok => false)
public_ipv4 = Discovery.ipaddress(:remote_node => host, :node => node, :type => :public)

@leifmadsen :remote_node should contain the 'node' object of the remote node (search response) -- the :node => node is used to compare the remote node to local node and test if they are in the same cloud, same AZ, etc. if you use discovery_ipaddress and discovery_search / discovery_all you can omit the :node => node param, since it's already injected into the Recipe DSL.

Hmmm for whatever reason I can't seem to get it to work like that. (Note that I'm working on updating the readme.md with information you've posted here and will submit a pull request today.)

My example:

host = Discovery.search("provisioning_server", :node => node)
public_ipv4 = Discovery.ipaddress(:remote_node => host, :type => :public)

However adding back in the :node => node to the ipaddress seems to cause things to work as expected.

@leifmadsen you are explicitly not using the example I posted earlier and instead using the module methods themselves directly.

compare mine:

host = discovery_search("rabbitmq", :empty_ok => false)
ipaddress = discovery_ipaddress(:remote_node => host)

yours:

host = Discovery.search("provisioning_server", :node => node)
public_ipv4 = Discovery.ipaddress(:remote_node => host, :type => :public)

As you can see, my example shows the usage of the Recipe DSL for Discovery -- whereas yours uses the underlying methods directly. If you prefer to use the underlying methods directly, as you've noted, you will need to pass in a 'node' object from whatever context you are calling the method in. i.e. recipe.

The Recipe DSL is defined/mixed in here: https://github.com/fujin/chef-discovery/blob/master/libraries/recipe.rb#L17 as you can see, this takes care of inserting the node from the calling context

OK, well that makes sense. I was using the non-DSL version as that is what is documented on the readme. I'll note this in my documentation and provide a pull request about this issue soon. Thanks.

@leifmadsen thanks, and apologies. I meant to update the documentation when I added the newer form Recipe DSL but it slipped my mind.

No worries. If that is actually the preferred method now, then I will update all documentation to reflect that.

Updated docs in release v0.1.7