Class: VagrantPlugins::Babushka::Provisioner

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vagrant-babushka/provisioner.rb

Overview

The main implementation class for the Babushka provisioner

Defined Under Namespace

Classes: CurlMissingError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#groupObject

Returns the value of attribute group.



29
30
31
# File 'lib/vagrant-babushka/provisioner.rb', line 29

def group
  @group
end

#usernameObject

Returns the value of attribute username.



29
30
31
# File 'lib/vagrant-babushka/provisioner.rb', line 29

def username
  @username
end

Instance Method Details

#configure(root_config) ⇒ Object

Called with the root configuration of the machine so the provisioner can add some configuration on top of the machine.

During this step, and this step only, the provisioner should modify the root machine configuration to add any additional features it may need. Examples include sharing folders, networking, and so on. This step is guaranteed to be called before any of those steps are done so the provisioner may do that.



40
41
42
43
# File 'lib/vagrant-babushka/provisioner.rb', line 40

def configure(root_config)
  @username = root_config.ssh.username || root_config.ssh.default.username
  share_local_deps(root_config) if config.local_deps_path
end

#detect_ssh_groupObject

Determines and saves the name of the SSH user’s primary group



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/vagrant-babushka/provisioner.rb', line 64

def detect_ssh_group
  @group = ""

  # Save stdout into @group
  communicate.execute("id -gn #{escape username}") do |type, data|
    @group += data if type == :stdout
  end

  # Remove trailing newline from command output
  @group.gsub! /\n\Z/, ""
end

#do_babushka_runObject

Invokes Babushka on the virtual machine to meet requested deps

Since Babushka can only meet one dep at a time, if multiple deps are in the meet list (the user has requested multiple deps to be run) then we have to have multiple invokations, once for each dep.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/vagrant-babushka/provisioner.rb', line 112

def do_babushka_run
  if config.deps.empty?
    ui.warn <<-END.gsub(/ {12}|\n\Z/, ""), :scope => name
      Didn't find any Babushka deps to be met on the VM.
      Add some to your Vagrantfile: babushka.meet 'my dep'
    END
  else
    ui.info "Provisioning VM using Babushka...", :scope => name
    config.deps.each do |dep|
      ui.info "Meeting Babushka dep '#{dep.id}'", :scope => name
      ui.info "Executing '#{command_for(dep).strip}'...", :scope => name
      options = {:error_key => "vagrant_babushka_provision_error"}
      communicate.execute command_for(dep), options, &log_stdout
    end
  end
end

#prepareObject

Performs preparation necessary before Babushka can be invoked

Installs Babushka if it’s not available. If Babushka needs to be installed, cURL will be installed first so that Babushka can be downloaded over HTTPS (as wget may not support HTTPS).



95
96
97
98
99
100
101
102
103
104
# File 'lib/vagrant-babushka/provisioner.rb', line 95

def prepare
  unless in_path? "babushka"
    # Install cURL first to ensure we can download over HTTPS
    install_curl! unless in_path? "curl"
    create_destination!
    install_babushka!
    patch_babushka_binary!
    ui.info "\n\n\n"
  end
end

#provisionObject

This is the method called when the actual provisioning should be done. The communicator is guaranteed to be ready at this point, and any shared folders or networds are already set up.



48
49
50
51
52
53
# File 'lib/vagrant-babushka/provisioner.rb', line 48

def provision
  detect_ssh_group
  render_messages
  prepare
  do_babushka_run
end

#render_messagesObject

Renders the messages to the log output

The config object maintains a list of “messages” to be shown when provisioning occurs, since there’s no way to show messages at the time of configuration actually occurring. This displays the messages that were saved.



82
83
84
85
86
87
88
# File 'lib/vagrant-babushka/provisioner.rb', line 82

def render_messages
  config.messages.each do |(level, info, caller)|
    info = "vagrant-babushka: #{info}"
    info += "\nIn #{caller.first}" unless caller.nil?
    ui.send level.to_sym, info.to_s, :scope => name
  end
end

#share_local_deps(root_config) ⇒ Object

Shares local deps with the virtual machine



56
57
58
59
60
61
# File 'lib/vagrant-babushka/provisioner.rb', line 56

def share_local_deps(root_config)
  local_path = config.local_deps_path
  remote_path = "/home/#{escape username}/babushka-deps"
  opts = {:id => 'babushka_deps', :nfs => false}
  root_config.vm.synced_folder local_path, remote_path, opts
end