0

I'm trying to test a recipe that uses the sudo community cookbook.

I have installed berks locally, I have created a Berksfile and added the following to it:

source "https://supermarket.getchef.com"

metadata

cookbook 'sudo'

and issued the commands berks install and berks vendor

nonetheless, I'm still getting the error

[2016-11-30T12:32:53+00:00] ERROR: No resource or method named `sudo' for `Chef::Recipe "default"'

pointing to this part of my recipe:

49>> sudo 'reboot_bot' do
50:    user 'reboot_bot'
51:    nopasswd true
52:    commands [
53:      '/sbin/reboot'
54:    ]
55:  end

Anything else that needs to be done and I'm missing? Something I'm doing wrong?

Tom Klino
  • 2,358
  • 5
  • 35
  • 60
  • Which kind of test are you running ? if chefspec you'll have to include chefspec/berkshelf in your spec_helper. see [The documentation](https://github.com/sethvargo/chefspec#berkshelf) of chefspec – Tensibai Nov 30 '16 at 14:10
  • not actually running a test perse, just testing a recipe. I want to run it in kitchen before running in prod. But the recipe refuses to run as you can see in my question – Tom Klino Nov 30 '16 at 14:39
  • 1
    Running in kitchen is running functional test. Btw, kitchen should use berkshelf to resolve dependencies, you did add a `depends 'sudo'` in your cookbook `metadata.rb` right ? (if not, you have too, chef client won't read the Berksfile, and that's the reason of the metadata option in it, take the dependencies from the metadata file, specifying them under is when you wish to use a different source than the default at top) – Tensibai Nov 30 '16 at 14:44

1 Answers1

1

You shouldn't need to put this in the Berksfile, that is only for overrides when you need to load from a non-standard location. Add the sudo cookbook as a dependency of your own cookbook in the metadata.rb and then Berks will see it and more importantly Chef will also see it (Chef doesn't know about Berksfiles) and will make sure to load the custom resource.

coderanger
  • 52,400
  • 4
  • 52
  • 75