Implements the logic needed to read the roles and associated information
# File lib/smart_proxy_ansible/roles_reader.rb, line 11 def list_roles roles_path.split(':').map { |path| read_roles(path) }.flatten end
# File lib/smart_proxy_ansible/roles_reader.rb, line 24 def logger # Return a different logger depending on where ForemanAnsibleCore is # running from if defined?(::Foreman::Logging) ::Foreman::Logging.logger('foreman_ansible') else ::Proxy::LogBuffer::Decorator.instance end end
# File lib/smart_proxy_ansible/roles_reader.rb, line 15 def roles_path(roles_line = roles_path_from_config) # Default to /etc/ansible/roles if none found return DEFAULT_ROLES_PATH if roles_line.empty? roles_path_key = roles_line.first.split('=').first.strip # In case of commented roles_path key "#roles_path", return default return DEFAULT_ROLES_PATH unless roles_path_key == 'roles_path' roles_line.first.split('=').last.strip end
# File lib/smart_proxy_ansible/roles_reader.rb, line 36 def read_roles(roles_path) rescue_and_raise_file_exception ReadRolesException, roles_path, 'roles' do Dir.glob("#{roles_path}/*").map do |path| path.split('/').last end end end
# File lib/smart_proxy_ansible/roles_reader.rb, line 54 def rescue_and_raise_file_exception(exception, path, type) yield rescue Errno::ENOENT, Errno::EACCES => e logger.debug(e.backtrace) exception_message = "Could not read Ansible #{type} " "#{path} - #{e.message}" raise exception.new(exception_message), exception_message end
# File lib/smart_proxy_ansible/roles_reader.rb, line 45 def roles_path_from_config rescue_and_raise_file_exception ReadConfigFileException, DEFAULT_CONFIG_FILE, 'config file' do File.readlines(DEFAULT_CONFIG_FILE).select do |line| line =~ /^\s*roles_path/ end end end