lib/itamae-mitsurin/mitsurin/task_base.rb in itamae-mitsurin-0.12 vs lib/itamae-mitsurin/mitsurin/task_base.rb in itamae-mitsurin-0.13

- old
+ new

@@ -1,5 +1,8 @@ +require 'json' +require 'highline' +require "tmpdir" module ItamaeMitsurin module Mitsurin module TaskBase @@ -28,11 +31,11 @@ recipes = [] JSON.parse(File.read("roles/#{role}.json"))['run_list'].each do |recipe| if /recipe\[(.+)::(.+)\]/ === recipe recipes << {recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2')} else - recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => nil} + recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => 'default'} end end recipes end @@ -40,11 +43,11 @@ recipes = [] JSON.parse(File.read(node_file))['run_list'].each do |recipe| if /recipe\[(.+)::(.+)\]/ === recipe recipes << {recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2')} else - recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => nil} unless /role\[(.+)\]/ === recipe + recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => 'default'} unless /role\[(.+)\]/ === recipe end end recipes end @@ -58,9 +61,19 @@ File.open "tmp-nodes/#{filename}.json", 'w' do |f| f.flock File::LOCK_EX yield f f.flock File::LOCK_UN end + end + + def write_tmp_json(filename) + path = Dir.mktmpdir("mitsurin-") + open("#{path}/#{filename}.json", "w") do |f| + f.flock File::LOCK_EX + yield f + f.flock File::LOCK_UN + end + path end def hl HighLine.new end