0
votes

I'm trying to create a Ubuntu machine with Vagrant and Chef Solo. So, I've created a simple Vagrantfile and a simple recipe, just to test it. But I'm facing with the following error message:

Recipe Compile Error in /tmp/vagrant-chef/71c53eb7bf7c3d22bf315b2652372569/cookbooks/teste/recipes/default.rb

==> default: NoMethodError ==> default: undefined method `[]' for nil:NilClass

==> default: Cookbook Trace: ==> default: /tmp/vagrant-chef/f7fdc686ea08792157234990dd67a042/cookbooks/apt/recipes/default.rb:33:in from_file' ==> default: /tmp/vagrant-chef/71c53eb7bf7c3d22bf315b2652372569/cookbooks/teste/recipes/default.rb:3:in `from_file'

==> default: Relevant File Content: ==> default: /tmp/vagrant-chef/f7fdc686ea08792157234990dd67a042/cookbooks/apt/recipes/default.rb:

==> default: 26: file '/var/lib/apt/periodic/update-success-stamp' do
==> default: 27: owner 'root'
==> default: 28: group 'root'
==> default: 29: action :nothing
==> default: 30: end
==> default: 31:
==> default: 32: # If compile_time_update run apt-get update at compile time
==> default: 33>> if node['apt']['compile_time_update'] && apt_installed?
==> default: 34: apt_update('compile time') do
==> default: 35: frequency node['apt']['periodic_update_min_delay']
==> default: 36: ignore_failure true
==> default: 37: end.run_action(:periodic)
==> default: 38: end
==> default: 39:
==> default: 40: apt_update 'periodic' do
==> default: 41: frequency node['apt']['periodic_update_min_delay']
==> default: 42: end


Below there are my files:

Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"

  config.berkshelf.enabled = true
  config.berkshelf.berksfile_path = "./cookbooks/teste/Berksfile"

  config.vm.provision "chef_solo" do |chef|
   chef.install = false
   chef.add_recipe "teste"
  end
end

Berksfile

source 'https://supermarket.chef.io'

metadata

cookbook 'apt'
cookbook 'java'

default.rb

include_recipe 'apt::default'
include_recipe 'java::default'

attributes.rb

default['java']['install_flavor'] = 'openjdk'
default['java']['jdk_version'] = '8'
default['java']['accept_license_agreement'] = true

metadata.rb

name 'teste'
maintainer 'The Authors'
maintainer_email '[email protected]'
license 'All Rights Reserved'
description 'Installs/Configures teste'
long_description 'Installs/Configures teste'
version '0.1.0'
chef_version '>= 12.1' if respond_to?(:chef_version)

About my configuration:

Chef Development Kit Version: 2.3.4
chef-client version: 13.4.19
berks version: 6.3.1
kitchen version: 1.17.0
inspec version: 1.36.1

Vagrant 2.0.1

macOS Sierra (10.12.6)
1

1 Answers

0
votes

You need to add depends 'apt' and depends 'java' to the metadata of your cookbook. Then remove the cookbook lines in the Berksfile as they are redundant.