Class: Berkshelf::Vagrant::Config

Inherits:
Object
  • 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.



33
34
35
36
37
38
39
40
41
42
# File 'lib/berkshelf/vagrant/config.rb', line 33

def initialize
  super

  @berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
  @except         = Array.new
  @only           = Array.new
  @node_name      = Berkshelf::Config.instance.chef.node_name
  @client_key     = Berkshelf::Config.instance.chef.client_key
  @enabled        = File.exist?(@berksfile_path)
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



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

def berksfile_path
  @berksfile_path
end

#client_keyString

Returns a filepath to a chef client key to use to authenticate with the remote chef server to upload cookbooks when using the chef client provisioner.

Returns:

  • (String)

    a filepath to a chef client key to use to authenticate with the remote chef server to upload cookbooks when using the chef client provisioner



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

def client_key
  @client_key
end

#enabledBoolean

Returns disable of use Berks in Vagrant.

Returns:

  • (Boolean)

    disable of use Berks in Vagrant



11
12
13
# File 'lib/berkshelf/vagrant/config.rb', line 11

def enabled
  @enabled
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



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

def except
  @except
end

#node_nameString

Returns the Chef node name (client name) to use to authenticate with the remote chef server to upload cookbooks when using the chef client provisioner.

Returns:

  • (String)

    the Chef node name (client name) to use to authenticate with the remote chef server to upload cookbooks when using the chef client provisioner



26
27
28
# File 'lib/berkshelf/vagrant/config.rb', line 26

def node_name
  @node_name
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



16
17
18
# File 'lib/berkshelf/vagrant/config.rb', line 16

def only
  @only
end

Instance Method Details

#validate(machine) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/berkshelf/vagrant/config.rb', line 56

def validate(machine)
  errors = Array.new

  unless [TrueClass, FalseClass].include?(enabled.class)
    errors << "A value for berkshelf.enabled can be true or false."
  end

  if enabled
    if machine.config.berkshelf.berksfile_path.nil?
      errors << "berkshelf.berksfile_path cannot be nil."
    end

    unless File.exist?(machine.config.berkshelf.berksfile_path)
      errors << "No Berksfile was found at #{machine.config.berkshelf.berksfile_path}."
    end

    if !except.empty? && !only.empty?
      errors << "A value for berkshelf.empty and berkshelf.only cannot both be defined."
    end

    if machine.env.config_global.vm.provisioners.any? { |prov| prov.name == :chef_client }
      if machine.config.berkshelf.node_name.nil?
        errors << "A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
      end

      if machine.config.berkshelf.client_key.nil?
        errors << "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

  { "berkshelf configuration" => errors }
end