customink-webops/hostsfile

Getting "ArgumentError: Cannot find a recipe matching default in cookbook hostsfile"

kevinburke opened this issue · 17 comments

I'm trying to follow the instructions to install the recipe, and getting the above error. Looking at the repo, it's clear there is no recipes folder. All of the other LWRP's I saw had at least one recipe in the recipes folder.

In another cookbook I'm trying to do this:

include_recipe "hostsfile"

and getting the above error message.

Am I missing something?

Can you post a link to you github repo? What version of Chef? You shouldn't need to include_recipe to use the LWRP anyway.

I'm running Chef 10.14.2. I was just following your repo's README, which says that I should "simply include this recipe" to get access to the LWRP. This obviously fails, because there are no recipes attached to your LWRP.

Instead, I needed something like this:

hostsfile_entry "127.0.0.1" do
    hostname "localhost"
    action :append
    provider "hostsfile_entry"
end

Which works without a recipe include.

Right... It doesn't say to actually type 'include_recipe 'hostsfile'`, since it's not actually a recipe. It's an LWRP. It doesn't make sense to have a default recipe, since I don't know what you would want to do in your hostsfile.

In that case I'm not sure we are reading the same document. The Usage section of the README says:

Then, simply include this recipe and you'll be granted access to this LWPR:

# your_recipe.rb
include_recipe 'hostsfile'

I don't know that much about Chef. include_recipe is a fairly common method for making other cookbooks available in your project, I assumed it would work here and was confused about what to do when I was told no default recipe exists. I'd rather not have to look up a whole bunch of information about LWRP's, and providers, just to get this to run properly.

In general when writing documentation, it's a good idea to assume that people are not going to read, or be total experts in your field, and that people are going to copy/paste code samples at will. Easier to provide a code sample someone can easily figure out how to adapt, such as:

hostsfile_entry "127.0.0.1" do
    hostname "localhost"
    action :append
    provider "hostsfile_entry"
end

I can look at that, and know I need to change the 127.0.0.1 and the "localhost" to get it to work.

Kevin,

I just updated the readme. You definitely shouldn't include the recipe in yours but your cookbook's metadata.rb should specify that it depends on the hostsfile cookbook.

# your cookbook's metadata.rb
depends 'hostsfile'

With that in place you should be set and also should be able to remove the provider declaration from your cookbook.

-Nathen

Thanks! I haven't seen depends before. I'll try it this afternoon.

Just got stung by this myself.

Please take the "include_recipe" bit off https://github.com/customink-webops/hostsfile#usage

Thanks

@dan77g where are you seeing that? There's no reference to include_recipe at the URL you referenced:

Screen Shot 2013-03-12 at 3 38 26 PM

My bad ...
That was a stale howto from a different browser tab. Sorry for the confusion!

On an unrelated note, any idea why I would be getting

[2013-03-13T11:33:11+00:00] FATAL: NoMethodError: ruby_block[block_until_nodes](app_tier::default line 80) had an error: NoMethodError: undefined method `hostsfile_entry' for Chef::Resource::RubyBlock

when I do

nodes.each do |nd|
  if nd[:network][:interfaces][:eth1] then
    hostsfile_entry nd[:ipaddress] do
      hostname nd[:hostname]
      action :create_if_missing
    end
    Chef::Log.info("#{nd[:name]} has hostname #{nd[:hostname]} and has IP address #{nd[:ipaddress]}")
  end
end

I have:
depends 'hostsfile'

in my metadata.rb for this cookbook as suggested.

@dan77g Can you point me to the full recipe? Gist or GitHub repo...

Thanks ... there's a recipe file at https://gist.github.com/dan77g/5173216

Apart from that, it's just the
depends 'hostsfile'
in metadata.rb.

You can't use LWRPs (easily) in a Ruby block because of scope. You also don't need a ruby_block as you've done there, from what I can tell.

Didn't realise the scope issue, thanks. (I would love to know where that was documented ...)
(And yes, the ruby_block is cruft in this instance ....)

Just to be pedantic, you still have include_recipe in your blog about the same. Might confuse some folks, like me, until they stumble upon the full repo.

@simonmorley I don't have access to change that blog post anymore.

Ah. That's annoying for you.