Class: VagrantPlugins::ChefApply::Provisioner

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-chef-apply/provisioner.rb

Instance Method Summary collapse

Instance Method Details

#provisionObject



7
8
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
# File 'lib/vagrant-chef-apply/provisioner.rb', line 7

def provision
  command = "chmod +x #{config.upload_path} && chef-apply #{config.upload_path}"

  # Upload the script to the machine
  @machine.communicate.tap do |comm|
    # Reset upload path permissions for the current ssh user
    user = @machine.ssh_info[:username]
    comm.sudo("chown -R #{user} #{config.upload_path}",
              :error_check => false)
    
    comm.upload(config.path, config.upload_path)
    
    @machine.ui.info(I18n.t("vagrant.provisioners.chef_apply.running",
                            script: config.path))
      
    # Execute it with sudo
    comm.sudo(command) do |type, data|
      if [:stderr, :stdout].include?(type)
        # 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
    end
  end
end