Module: Vagrant::Action::Builtin::MixinProvisioners

Included in:
Provision, ProvisionerCleanup
Defined in:
lib/vagrant/action/builtin/mixin_provisioners.rb

Instance Method Summary collapse

Instance Method Details

#provisioner_instances(env) ⇒ Array<Provisioner, Hash>

This returns all the instances of the configured provisioners. This is safe to call multiple times since it will cache the results.

Returns:

  • (Array<Provisioner, Hash>)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant/action/builtin/mixin_provisioners.rb', line 9

def provisioner_instances(env)
  return @_provisioner_instances if @_provisioner_instances

  # Make the mapping that'll keep track of provisioner => type
  @_provisioner_types = {}

  # Get all the configured provisioners
  @_provisioner_instances = env[:machine].config.vm.provisioners.map do |provisioner|
    # Instantiate the provisioner
    klass  = Vagrant.plugin("2").manager.provisioners[provisioner.type]

    # This can happen in the case the configuration isn't validated.
    next nil if !klass

    result = klass.new(env[:machine], provisioner.config)

    # Store in the type map so that --provision-with works properly
    @_provisioner_types[result] = provisioner.type

    # Build up the options
    options = {
      name: provisioner.name,
      run:  provisioner.run,
    }

    # Return the result
    [result, options]
  end

  return @_provisioner_instances.compact
end

#provisioner_type_map(env) ⇒ Object

This will return a mapping of a provisioner instance to its type.



43
44
45
46
47
48
49
# File 'lib/vagrant/action/builtin/mixin_provisioners.rb', line 43

def provisioner_type_map(env)
  # Call this in order to initial the map if it hasn't been already
  provisioner_instances(env)

  # Return the type map
  @_provisioner_types
end