The apt recipe won't install within my recipe
Asked Answered
L

1

6

I am attempting to create my first Chef recipe with Vagrant and have run into an issue at the very first step. The first line of my recipe is:

include_recipe "apt"

But when I try and vagrant provision I get the following error:

==> default: [2014-09-21T07:15:42+00:00] WARN: MissingCookbookDependency:
==> default: Recipe `apt` is not in the run_list, and cookbook 'apt'
==> default: is not a dependency of any cookbook in the run_list.  To load this recipe,
==> default: first add a dependency on cookbook 'apt' in the cookbook you're
==> default: including it from in that cookbook's metadata.
==> default: [2014-09-21T07:15:42+00:00] ERROR: No resource or method named `apt_installed?' for `Chef::Recipe "default"'
==> default: [2014-09-21T07:15:42+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

This is what my Vagrantfile looks like:

Vagrant.configure("2") do |config|
  config.omnibus.chef_version = :latest
  config.vm.box = "precise32"
  config.vm.box_url = "http://files.vagrantup.com/precise32.box"
  config.vm.network :private_network, ip: "192.168.42.42"
  config.vm.synced_folder "./", "/var/www", group: "www-data", mount_options: ["dmode=777,fmode=664"]

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = "cookbooks"
    chef.data_bags_path = "data_bags"
    chef.add_recipe "divups"
  end
end

And the divups default.rb file looks like this:

include_recipe "apt"
puts "So we made it this far..."

What is strange though is that I can install apt if I include it in my Vagrantfile file above chef.add_recipe "divups", but if I try and include in within my custom recipe, I get the errors I posted above.

Is there something I'm missing or doing wrong?

Lully answered 21/9, 2014 at 7:38 Comment(0)
U
10

You are calling a recipe from another cookbook, so you need to add it as a dependency in your cookbook's metadata.

Add the following line to the metadata.rb file (in the divups cookbook):

depends "apt"
Unseen answered 21/9, 2014 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.