Module: ItamaeSpec::Task::Base
- Included in:
- BaseTask
- Defined in:
- lib/itamae-spec/task/base.rb
Constant Summary collapse
- RoleLoadError =
Class.new(StandardError)
- EnvironmentsLoadError =
Class.new(StandardError)
Class Method Summary collapse
- .get_environments(node_file) ⇒ Object
- .get_node_recipes(node_file) ⇒ Object
- .get_role_recipes(role) ⇒ Object
- .get_roles(node_file) ⇒ Object
- .write_tmp_nodes(filename) ⇒ Object
Class Method Details
.get_environments(node_file) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/itamae-spec/task/base.rb', line 58 def get_environments(node_file) environments = JSON.parse(File.read(node_file))['environments']['set'] rescue JSON::ParserError raise EnvironmentsLoadError, "JSON Parser Faild. - #{node_file}" rescue Errno::ENOENT raise EnvironmentsLoadError, "No such node file or directory - #{node_fie}" else environments end |
.get_node_recipes(node_file) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/itamae-spec/task/base.rb', line 85 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/itamae-spec/task/base.rb', line 68 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 |
.get_roles(node_file) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/itamae-spec/task/base.rb', line 43 def get_roles(node_file) roles = [] JSON.parse(File.read(node_file))['run_list'].each do |recipe| if /role\[(.+)\]/.match?(recipe) roles << 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 roles end |
.write_tmp_nodes(filename) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/itamae-spec/task/base.rb', line 104 def write_tmp_nodes(filename) Itamae.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 |