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

Instance Method Details

#berks(command, args) ⇒ String #berks(command, args, options) ⇒ String

Execute a berkshelf command with the given arguments and flags.

Overloads:

  • #berks(command, args) ⇒ String

    Parameters:

    • berks (String)

      CLI command to run

    • any (Object)

      number of arguments to pass to CLI

  • #berks(command, args, options) ⇒ String

    Parameters:

    • berks (String)

      CLI command to run

    • any (Object)

      number of arguments to pass to CLI

    • options (Hash)

      to convert to flags for the CLI

Returns:

  • (String)

    output of the command

Raises:



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

Parameters:

  • env (Vagrant::Environment)

Returns:

  • (Boolean)


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.

Returns:

  • (String)


49
50
51
# File 'lib/berkshelf/vagrant/env_helpers.rb', line 49

def cache_file(env)
  File.expand_path(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

Parameters:

  • env (Vagrant::Environment)

Returns:

  • (Boolean)


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

Parameters:

  • env (Vagrant::Environment)

Returns:

  • (Boolean)


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

Parameters:

  • env (Vagrant::Environment)

Returns:

  • (Boolean)


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

Parameters:

  • name (Symbol)

    name of provisioner to filter

  • env (Vagrant::Environment, Hash)

    environment to inspect

Returns:

  • (Array)


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