class Proxy::Ansible::ReaderHelper
Helper for Playbooks Reader
Constants
- DEFAULT_COLLECTIONS_PATHS
- DEFAULT_CONFIG_FILE
Public Class Methods
collections_paths()
click to toggle source
# File lib/smart_proxy_ansible/reader_helper.rb, line 9 def collections_paths config_path(path_from_config('collections_paths'), DEFAULT_COLLECTIONS_PATHS) end
config_path(config_line, default)
click to toggle source
# File lib/smart_proxy_ansible/reader_helper.rb, line 13 def config_path(config_line, default) return default if config_line.empty? config_line_key = config_line.first.split('=').first.strip # In case of commented roles_path key "#roles_path" or #collections_paths, return default return default if ['#roles_path', '#collections_paths'].include?(config_line_key) config_line.first.split('=').last.strip end
path_from_config(config_key)
click to toggle source
# File lib/smart_proxy_ansible/reader_helper.rb, line 23 def path_from_config(config_key) File.readlines(DEFAULT_CONFIG_FILE).select do |line| line =~ /^\s*#{config_key}/ end rescue Errno::ENOENT, Errno::EACCES => e RolesReader.logger.debug(e.backtrace) message = "Could not read Ansible config file #{DEFAULT_CONFIG_FILE} - #{e.message}" raise ReadConfigFileException.new(message), message end
playbook_or_role_full_name(path)
click to toggle source
# File lib/smart_proxy_ansible/reader_helper.rb, line 33 def playbook_or_role_full_name(path) parts = path.split('/') playbook = parts.pop.sub(/\.ya?ml/, '') parts.pop collection = parts.pop author = parts.pop "#{author}.#{collection}.#{playbook}" end