Method: Vagrant::Provisioners::ChefClient#run_chef_client

Defined in:
lib/vagrant/provisioners/chef_client.rb

#run_chef_clientObject

Raises:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/vagrant/provisioners/chef_client.rb', line 91

def run_chef_client
  command_env = config.binary_env ? "#{config.binary_env} " : ""
  command = "#{command_env}#{chef_binary_path("chef-client")} -c #{config.provisioning_path}/client.rb -j #{config.provisioning_path}/dna.json"

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

    exit_status = env[:vm].channel.sudo(command) 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.
      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