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.



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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vagrant/action/builtin/mixin_provisioners.rb', line 12

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

    # Set top level provisioner name to provisioner configs name if top level name not set.
    # This is mostly for handling the shell provisioner, if a user has set its name like:
    #
    #   config.vm.provision "shell", name: "my_provisioner"
    #
    # Where `name` is a shell config option, not a top level provisioner class option
    #
    # Note: `name` is set to a symbol, since it is converted to one via #Config::VM.provision
    provisioner_name = provisioner.name
    if !provisioner_name
      if provisioner.config.respond_to?(:name) &&
          provisioner.config.name
        provisioner_name = provisioner.config.name.to_sym
      end
    else
      provisioner_name = provisioner_name.to_sym
    end

    # Build up the options
    options = {
      name: provisioner_name,
      run:  provisioner.run,
      before:  provisioner.before,
      after:  provisioner.after,
      communicator_required: provisioner.communicator_required,
    }

    # Return the result
    [result, options]
  end

  @_provisioner_instances = sort_provisioner_instances(@_provisioner_instances)
  return @_provisioner_instances.compact
end