Class: VagrantPlugins::CookbookFetcher::SetChefPathsAction

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-cookbook-fetcher/action_set_chef_paths.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SetChefPathsAction

Returns a new instance of SetChefPathsAction.



5
6
7
# File 'lib/vagrant-cookbook-fetcher/action_set_chef_paths.rb', line 5

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



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
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vagrant-cookbook-fetcher/action_set_chef_paths.rb', line 9

def call(env)
  # there has got to be a better way
  chef_solo = env[:machine].config.vm.provisioners.find { |p| p.type === :chef_solo }
  vcf_config = env[:machine].config.cookbook_fetcher

  if chef_solo then

    unless vcf_config.disable then
      solo_cfg = chef_solo.config

      Dir.chdir(env[:root_path]) do
        # In Vagrant 1.2.x+, these are all arrays
        solo_cfg.roles_path.push [:host, "combined/roles"]
        solo_cfg.data_bags_path.push [:host, "combined/data_bags"]
        
        # The first time we fetch cookbooks, we store the cookbook order in a file.
        unless File.exists?(".cookbook-order") then
          env[:ui].error "Cookbook Fetcher checkout could find not a .cookbook-order file.  You need to run provision with checkout enabled at least once (or else disable cookbook fetcher)."
          return
        end

        # For cookbook path, Vagrant defaults to this:
        # [[:host, "cookbooks"], [:vm, "cookbooks"]]
        # But we're overriding that.
        solo_cfg.cookbooks_path = []

        # Read from filesystem
        IO.readlines(".cookbook-order").each do |line| 
          solo_cfg.cookbooks_path.push [ :host, line.chomp ]
        end

      end
    end
  end

  # Continue daisy chain
  @app.call(env) 
end