Class: Berkshelf::Vagrant::Config
- Inherits:
-
Object
- Object
- Berkshelf::Vagrant::Config
- Defined in:
- lib/berkshelf/vagrant/config.rb
Overview
Instance Attribute Summary collapse
-
#berksfile_path ⇒ String
Path to the Berksfile to use with Vagrant.
-
#client_key ⇒ 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.
-
#enabled ⇒ Boolean
Disable of use Berks in Vagrant.
-
#except ⇒ Array<Symbol>
Cookbooks in all other groups except for these will be installed and copied to Vagrant’s shelf.
-
#node_name ⇒ 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.
-
#only ⇒ Array<Symbol>
Only cookbooks in these groups will be installed and copied to Vagrant’s shelf.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
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_path ⇒ String
Returns 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_key ⇒ String
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.
31 32 33 |
# File 'lib/berkshelf/vagrant/config.rb', line 31 def client_key @client_key end |
#enabled ⇒ Boolean
Returns disable of use Berks in Vagrant.
11 12 13 |
# File 'lib/berkshelf/vagrant/config.rb', line 11 def enabled @enabled end |
#except ⇒ Array<Symbol>
Returns 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_name ⇒ String
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.
26 27 28 |
# File 'lib/berkshelf/vagrant/config.rb', line 26 def node_name @node_name end |
#only ⇒ Array<Symbol>
Returns 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 |