Class: VagrantPlugins::Chef::Provisioner::ChefClient

Inherits:
Base
  • Object
show all
Includes:
VagrantWindows::Helper
Defined in:
lib/vagrant-windows/monkey_patches/plugins/provisioners/chef/provisioner/chef_client.rb

Instance Method Summary collapse

Methods included from VagrantWindows::Helper

#wait_if_rebooting, #win_friendly_path, #win_friendly_share_id

Constructor Details

#initialize(machine, config) ⇒ ChefClient

Returns a new instance of ChefClient.



13
14
15
16
17
# File 'lib/vagrant-windows/monkey_patches/plugins/provisioners/chef/provisioner/chef_client.rb', line 13

def initialize(machine, config)
  super
  @windows_machine = VagrantWindows::WindowsMachine.new(machine)
  @logger = Log4r::Logger.new("vagrant::provisioners::chef_client")
end

Instance Method Details

#run_chef_client_on_windowsObject

Raises:

  • (ChefError)


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
65
66
67
68
69
# File 'lib/vagrant-windows/monkey_patches/plugins/provisioners/chef/provisioner/chef_client.rb', line 31

def run_chef_client_on_windows
  if @config.run_list && @config.run_list.empty?
    @machine.ui.warn(I18n.t("vagrant.chef_run_list_empty"))
  end

  #################### START - monkey patched code ####################
  command_builder = ::VagrantWindows::Provisioners::ChefCommandBuilder.new(
    @windows_machine, @config, :client)
  
  command_builder.prepare_for_chef_run()
  command = command_builder.run_chef_command()
  ###################### END - monkey patched code ####################

  @config.attempts.times do |attempt|
    if attempt == 0
      @machine.env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
    else
      @machine.env.ui.info I18n.t("vagrant.provisioners.chef.running_client_again")
    end

    #################### START - monkey patched code ####################
    @windows_machine.reinitialize_network_shares()
    ###################### END - monkey patched code ####################

    exit_status = @machine.communicate.execute(command, :error_check => false) do |type, data|
      # Output the data with the proper color based on the stream.
      color = type == :stdout ? :green : :red

      @machine.env.ui.info(
        data, :color => color, :new_line => false, :prefix => false)
    end

    # There is no need to run Chef again if it converges
    return if exit_status == 0
  end

  # If we reached this point then Chef never converged! Error.
  raise ChefError, :no_convergence
end