Module: Berkshelf::Vagrant::EnvHelpers
- Includes:
- Buff::ShellOut, Vagrant::Util
- Included in:
- Action::Clean, Action::ConfigureChef, Action::Install, Action::LoadShelf, Action::Upload
- Defined in:
- lib/berkshelf/vagrant/env_helpers.rb
Overview
A module of common helper functions that can be mixed into Berkshelf::Vagrant actions
Constant Summary collapse
- BERKS_CONSTRAINT =
">= 3.0.0"
Instance Method Summary collapse
-
#berks(command, *args) ⇒ String
Execute a berkshelf command with the given arguments and flags.
- #berksfile_path(env) ⇒ Object
-
#berkshelf_enabled?(env) ⇒ Boolean
Determine if the Berkshelf plugin should be run for the given environment.
-
#cache_file(env) ⇒ String
A file to persist vagrant-berkshelf specific information in between Vagrant runs.
-
#chef_client?(env) ⇒ Boolean
Determine if the given vagrant environment contains a chef_client provisioner.
-
#chef_solo?(env) ⇒ Boolean
Determine if the given vagrant environment contains a chef_solo provisioner.
-
#provision_disabled?(env) ⇒ Boolean
Determine if –no-provision was specified.
-
#provisioners(name, env) ⇒ Array
Filter all of the provisioners of the given vagrant environment with the given name.
Instance Method Details
#berks(command, args) ⇒ String #berks(command, args, options) ⇒ String
Execute a berkshelf command with the given arguments and flags.
33 34 35 36 37 38 39 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 33 def berks(command, *args) if defined?(Bundler) Bundler.with_clean_env { run_berks(command, *args) } else run_berks(command, *args) end end |
#berksfile_path(env) ⇒ Object
41 42 43 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 41 def berksfile_path(env) env[:machine].env.vagrantfile.config.berkshelf.berksfile_path end |
#berkshelf_enabled?(env) ⇒ Boolean
Determine if the Berkshelf plugin should be run for the given environment
88 89 90 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 88 def berkshelf_enabled?(env) env[:machine].config.berkshelf.enabled end |
#cache_file(env) ⇒ String
A file to persist vagrant-berkshelf specific information in between Vagrant runs.
49 50 51 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 49 def cache_file(env) File.(File.join('.vagrant', 'machines', env[:machine].name.to_s, 'berkshelf'), env[:root_path].to_s) end |
#chef_client?(env) ⇒ Boolean
Determine if the given vagrant environment contains a chef_client provisioner
79 80 81 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 79 def chef_client?(env) provisioners(:chef_client, env).any? end |
#chef_solo?(env) ⇒ Boolean
Determine if the given vagrant environment contains a chef_solo provisioner
70 71 72 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 70 def chef_solo?(env) provisioners(:chef_solo, env).any? end |
#provision_disabled?(env) ⇒ Boolean
Determine if –no-provision was specified
97 98 99 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 97 def provision_disabled?(env) env.has_key?(:provision_enabled) && !env[:provision_enabled] end |
#provisioners(name, env) ⇒ Array
Filter all of the provisioners of the given vagrant environment with the given name
61 62 63 |
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 61 def provisioners(name, env) env[:machine].config.vm.provisioners.select { |prov| prov.name == name } end |