Class: Berkshelf::Vagrant::Config

Inherits:
Vagrant::Config::Base
  • Object
show all
Defined in:
lib/berkshelf/vagrant/config.rb

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



20
21
22
23
24
# File 'lib/berkshelf/vagrant/config.rb', line 20

def initialize
  @berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
  @except         = Array.new
  @only           = Array.new
end

Instance Attribute Details

#berksfile_pathString

Returns path to the Berksfile to use with Vagrant.

Returns:

  • (String)

    path to the Berksfile to use with Vagrant



8
9
10
# File 'lib/berkshelf/vagrant/config.rb', line 8

def berksfile_path
  @berksfile_path
end

#exceptArray<Symbol>

Returns cookbooks in all other groups except for these will be installed and copied to Vagrant’s shelf.

Returns:

  • (Array<Symbol>)

    cookbooks in all other groups except for these will be installed and copied to Vagrant’s shelf



18
19
20
# File 'lib/berkshelf/vagrant/config.rb', line 18

def except
  @except
end

#onlyArray<Symbol>

Returns only cookbooks in these groups will be installed and copied to Vagrant’s shelf.

Returns:

  • (Array<Symbol>)

    only cookbooks in these groups will be installed and copied to Vagrant’s shelf



13
14
15
# File 'lib/berkshelf/vagrant/config.rb', line 13

def only
  @only
end

Instance Method Details

#client_key=(value) ⇒ Object

Parameters:



32
33
34
# File 'lib/berkshelf/vagrant/config.rb', line 32

def client_key=(value)
  @client_key = File.expand_path(value)
end

#validate(env, errors) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/berkshelf/vagrant/config.rb', line 36

def validate(env, errors)
  if !except.empty? && !only.empty?
    errors.add("A value for berkshelf.empty and berkshelf.only cannot both be defined.")
  end

  if Berkshelf::Vagrant.chef_client?(env.config.global)
    if Berkshelf::Config.instance.chef.node_name.nil?
      errors.add("A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration.")
    end

    if Berkshelf::Config.instance.chef.client_key.nil?
      errors.add("A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration.")
    end
  end
end