Class: VagrantPlugins::RightscaleShim::Action::ConfigChefSolo
- Inherits:
-
Object
- Object
- VagrantPlugins::RightscaleShim::Action::ConfigChefSolo
- Defined in:
- lib/vagrant-rightscaleshim/action/config_chef_solo.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ConfigChefSolo
constructor
A new instance of ConfigChefSolo.
Constructor Details
#initialize(app, env) ⇒ ConfigChefSolo
Returns a new instance of ConfigChefSolo.
27 28 29 |
# File 'lib/vagrant-rightscaleshim/action/config_chef_solo.rb', line 27 def initialize(app, env) @app = app end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vagrant-rightscaleshim/action/config_chef_solo.rb', line 31 def call(env) shim_dir = env[:machine].config.rightscaleshim.shim_dir run_list_dir = env[:machine].config.rightscaleshim.run_list_dir one_time_runlist_file = env[:machine].config.rightscaleshim.one_time_runlist_file if shim_dir && !shim_dir.empty? && run_list_dir && !run_list_dir.empty? node_js_file = File.join(Dir.pwd, shim_dir, 'node.js') dispatch_dir = File.join(Dir.pwd, shim_dir, 'dispatch') FileUtils.mkdir_p dispatch_dir unless File.directory? dispatch_dir dispatch_files = Dir.entries(dispatch_dir).reject{|f| /^\.+/ =~ f}.sort_by{|f| File.mtime(File.join(dispatch_dir, f))} runlist = JSON.parse(File.read(File.join(Dir.pwd, run_list_dir, 'default.json'))) if File.exist? node_js_file runlist.merge! JSON.parse(File.read(node_js_file))["normal"] end # A specified runlist trumps all, but still inherits from default if ENV['runlist'] runlist_file = File.join(Dir.pwd, run_list_dir, "#{ENV['runlist']}.json") runlist.merge!(JSON.parse(File.read(runlist_file))) if File.exist? runlist_file elsif dispatch_files.length > 0 dispatch_file = File.join(dispatch_dir, dispatch_files.first) runlist.merge!(JSON.parse(File.read(dispatch_file))) one_time_runlist_file = dispatch_file env[:machine].config.rightscaleshim.one_time_runlist_file = dispatch_file end chef_solo_provisioners = env[:machine].config.vm.provisioners.select { |prov| prov.name == :chef_solo } if chef_solo_provisioners.any? chef_solo_provisioners.each do |solo_provisioner| solo_provisioner.config.json = { :rightscaleshim => { :shim_dir => shim_dir, :run_list_dir => run_list_dir, :one_time_runlist_file => one_time_runlist_file } }.merge(runlist) solo_provisioner.config.run_list = runlist['run_list'] end end end @app.call(env) end |