berkshelf / vagrant-berkshelf

A Vagrant plugin to add Berkshelf integration to the Chef provisioners
Other
379 stars 100 forks source link

"berksfile_path must be set" error #235

Closed phillipsnick closed 9 years ago

phillipsnick commented 9 years ago

Just playing with the new version 4.0.0 of vagrant-berkshelf.

Reading the usage in the readme it looks like this should default to 'Berksfile' if the file exists?

But on Vagrant up I get the following message

Bringing machine 'web' up with 'vmware_fusion' provider...
==> web: Loading Berkshelf datafile...
==> web: Sharing cookbooks with VM
There are errors in the configuration of this machine. Please fix
the following errors and try again:

Berkshelf:
* berksfile_path must be set

If I add the following line to my Vagrantfile it all works fine.

config.berkshelf.berksfile_path = "Berksfile"

Is this a bug or am I missing something here? (It's been a long day!)

vidluther commented 9 years ago

I had the same issue, so I created a new cookbook/Vagrant file to se if there were any syntax changes. The new config file had this line

config.berkshelf.berksfile_path = "./Berksfile" 

I added that to my cookbook, and it worked.

phillipsnick commented 9 years ago

Had a quick look in the code and have found the code which should handle this functionality. lib/vagrant-berkshelf/config.rb

Under the finalize method

      def finalize!
        @berksfile_path = nil if @berksfile_path == UNSET_VALUE

        if @enabled == UNSET_VALUE
          if @berksfile_path
            # Automatically enable if a Berksfile path was given
            @enabled = true
          elsif File.exist?("Berksfile")
            # Automatically enable when a Berksfile is persent
            @berksfile_path = "Berksfile"
            @enabled = true
          end
        end

        @enabled = false if @enabled == UNSET_VALUE

        @__finalized = true
      end

Assuming this isn't being called on my setup, quite new to Ruby so not sure how this finalize method is called.

My ruby version

ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161)
sethvargo commented 9 years ago

@vidluther @phillipsnick where are you running the Vagrant command from? You're correct in the behavior you describe, but I suspect that File.exist? call is running in the wrong directory. I bet we have to expand that bath relative to the Vagrantfile.

phillipsnick commented 9 years ago

I'm running it from the root of my project, where Vagrantfile, berksfile etc is located.

My setup can be seen here https://github.com/phillipsnick/nickphillips.co

sethvargo commented 9 years ago

@phillipsnick @vidluther #236 please

phillipsnick commented 9 years ago

Works perfectly :+1:

Thanks

vidluther commented 9 years ago

I haven't had a chance to test, and probably will not till mid week, so I'll take @phillipsnick 's word for it :)