class Proxy::Ansible::VariablesExtractor

Implements the logic needed to read the roles and associated information

Public Class Methods

extract_variables(role_path) click to toggle source
# 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.flat_map do |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
    loaded_yaml.keys
  end
end