Class: Migrant::Provisioners::ChefSolo

Inherits:
Base
  • Object
show all
Includes:
Util
Defined in:
lib/migrant/provisioners/chef_solo.rb

Instance Method Summary collapse

Methods inherited from Base

register, registered

Constructor Details

#initialize(env) ⇒ ChefSolo

Returns a new instance of ChefSolo.



9
10
11
# File 'lib/migrant/provisioners/chef_solo.rb', line 9

def initialize(env)
  super
end

Instance Method Details

#prepareObject



12
13
# File 'lib/migrant/provisioners/chef_solo.rb', line 12

def prepare
end

#runObject



52
53
54
# File 'lib/migrant/provisioners/chef_solo.rb', line 52

def run
  @environment.cloud.execute(['sudo chef-solo -c /tmp/migrant/solo.rb -j /tmp/migrant/dna.json'])
end

#uploadObject



14
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
# File 'lib/migrant/provisioners/chef_solo.rb', line 14

def upload
  server = @environment.server
  vagrant_environment = Vagrant::Environment.new
  vagrant_provisioner_config = vagrant_environment.config.vm.provisioners.first.config
  cookbook_paths = vagrant_provisioner_config.cookbooks_path
  roles_path = vagrant_provisioner_config.roles_path

  # Delete old stuff
  server.ssh "rm -rf /tmp/migrant && mkdir -p /tmp/migrant"
  
  @environment.ui.info "Uploading Cookbooks"
  cookbook_dest_paths = []
  cookbook_paths.each do |path|
    dest_path = "/tmp/migrant/#{File.basename(path)}"
    server.scp path, dest_path, :recursive => true
    cookbook_dest_paths << dest_path
  end
  role_dest_paths = []
  dest_path = "/tmp/migrant/#{File.basename(roles_path)}"
  server.scp roles_path, dest_path, :recursive => true
  role_dest_paths << dest_path

  @environment.ui.info "Generating Chef Solo Config Files"
  File.open('/tmp/migrant-solo.rb','w') do |f|
    f.write(TemplateRenderer.render('chef/solo.rb', {
      :cookbook_path => cookbook_dest_paths,
      :role_path => role_dest_paths
    }))
  end
  server.scp "/tmp/migrant-solo.rb","/tmp/migrant/solo.rb"
  File.open('/tmp/migrant-dna.json','w') do |f|
    f.write(TemplateRenderer.render('chef/dna.json', {
      :run_list => vagrant_provisioner_config.run_list
    }))
  end
  server.scp "/tmp/migrant-dna.json","/tmp/migrant/dna.json"
end