Class: VagrantPlugins::Chef::Provisioner::ChefSolo

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant-windows/monkey_patches/chef_solo.rb

Instance Method Summary collapse

Instance Method Details

#is_windowsObject



54
55
56
# File 'lib/vagrant-windows/monkey_patches/chef_solo.rb', line 54

def is_windows
  @machine.config.vm.guest.eql? :windows
end

#run_chef_solo_on_windowsObject

Raises:

  • (ChefError)


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
# File 'lib/vagrant-windows/monkey_patches/chef_solo.rb', line 15

def run_chef_solo_on_windows
  command_env = @config.binary_env ? "#{@config.binary_env} " : ""
  command_args = @config.arguments ? " #{@config.arguments}" : ""
  command_solo = "#{command_env}#{chef_binary_path("chef-solo")} "
  command_solo << "-c #{@config.provisioning_path}/solo.rb "
  command_solo << "-j #{@config.provisioning_path}/dna.json "
  command_solo << "#{command_args}"
  
  command = VagrantWindows.load_script_template("ps_runas.ps1",
    :options => {
      :user => machine.config.winrm.username, 
      :password => @machine.config.winrm.password,
      :cmd => "powershell.exe",
      :arguments => "-Command #{command_solo}"})

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

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

      # Note: Be sure to chomp the data to avoid the newlines that the
      # Chef outputs.
      @machine.env.ui.info(data.chomp, :color => color, :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