Module: ItamaeMitsurin::Mitsurin::Base
- Defined in:
- lib/itamae-mitsurin/mitsurin/base.rb
Constant Summary collapse
- RoleLoadError =
Class.new(StandardError)
Class Method Summary collapse
- .get_node_recipes(node_file) ⇒ Object
-
.get_role_recipes(role) ⇒ Object
def get_roles(node_file) roles = [] JSON.parse(File.read(node_file)).each do |role| roles << role.gsub(/role/, ‘1’) if /role/.match?(role) end.
- .handler_logger ⇒ Object
- .jq(*objs) ⇒ Object
- .write_tmp_json(filename) ⇒ Object
- .write_tmp_nodes(filename) ⇒ Object
Class Method Details
.get_node_recipes(node_file) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/itamae-mitsurin/mitsurin/base.rb', line 57 def get_node_recipes(node_file) recipes = [] JSON.parse(File.read(node_file))['run_list'].each do |recipe| if /recipe\[(.+)::(.+)\]/.match?(recipe) recipes << { recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2') } elsif /recipe\[(.+)\]/.match?(recipe) recipes << { recipe.gsub(/recipe\[(.+)\]/, '\1') => 'default' } elsif /role\[(.+)\]/.match?(recipe) recipes << get_role_recipes(recipe.gsub(/role\[(.+)\]/, '\1')) end end rescue JSON::ParserError raise RoleLoadError, "JSON Parser Faild. - #{node_file}" rescue Errno::ENOENT raise RoleLoadError, "No such node file or directory - #{node_fie}" else recipes end |
.get_role_recipes(role) ⇒ Object
def get_roles(node_file)
roles = []
JSON.parse(File.read(node_file))['run_list'].each do |role|
roles << role.gsub(/role\[(.+)\]/, '\1') if /role\[(.+)\]/.match?(role)
end
roles
end
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/itamae-mitsurin/mitsurin/base.rb', line 40 def get_role_recipes(role) recipes = [] JSON.parse(File.read("roles/#{role}.json"))['run_list'].each do |recipe| if /recipe\[(.+)::(.+)\]/.match?(recipe) recipes << { recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2') } elsif /recipe\[(.+)\]/.match?(recipe) recipes << { recipe.gsub(/recipe\[(.+)\]/, '\1') => 'default' } end end rescue JSON::ParserError raise RoleLoadError, "JSON Parser Faild. - roles/#{role}.json" rescue Errno::ENOENT raise RoleLoadError, "No such role file or directory - roles/#{role}.json" else recipes end |
.handler_logger ⇒ Object
103 104 105 |
# File 'lib/itamae-mitsurin/mitsurin/base.rb', line 103 def handler_logger default = {"handlers"=>[{"type"=>"json", "path"=>"itamae-log.json"}]} end |
.jq(*objs) ⇒ Object
76 77 78 79 80 |
# File 'lib/itamae-mitsurin/mitsurin/base.rb', line 76 def jq(*objs) par = nil objs.each {|obj| par = JSON.pretty_generate(obj, allow_nan: true, max_nesting: false) } par end |
.write_tmp_json(filename) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/itamae-mitsurin/mitsurin/base.rb', line 92 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 |
.write_tmp_nodes(filename) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/itamae-mitsurin/mitsurin/base.rb', line 82 def write_tmp_nodes(filename) ItamaeMitsurin.logger.info "Output attributes log file to: tmp-nodes/#{filename}.json" File.open "tmp-nodes/#{filename}.json", 'w' do |f| f.flock File::LOCK_EX yield f f.flock File::LOCK_UN end end |