Class: Proxy::Ansible::VariablesExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_ansible/variables_extractor.rb

Overview

Implements the logic needed to read the roles and associated information

Class Method Summary collapse

Class Method Details

.extract_variables(role_path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/smart_proxy_ansible/variables_extractor.rb', line 8

def extract_variables(role_path)
  role_files = Dir.glob("#{role_path}/defaults/**/*.yml") +
               Dir.glob("#{role_path}/defaults/**/*.yaml")
  role_files.reduce({}) do |memo, role_file|
    loaded_yaml = {}
    begin
      loaded_yaml = YAML.load_file(role_file)
    rescue Psych::SyntaxError
      raise ReadVariablesException.new "#{role_file} is not YAML file"
    end
    raise ReadVariablesException.new "Could not parse YAML file: #{role_file}" unless loaded_yaml.is_a? Hash
    memo.merge loaded_yaml
  end
end