class Proxy::Ansible::PlaybooksReader
Implements the logic needed to read the playbooks and associated information
Public Class Methods
get_playbooks_names(collections_path)
click to toggle source
# File lib/smart_proxy_ansible/playbooks_reader.rb, line 16 def get_playbooks_names(collections_path) glob_path("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| ReaderHelper.playbook_or_role_full_name(path) end end
playbooks(playbooks_to_import)
click to toggle source
# File lib/smart_proxy_ansible/playbooks_reader.rb, line 10 def playbooks(playbooks_to_import) ReaderHelper.collections_paths.split(':').reduce([]) do |playbooks, path| playbooks.concat(read_collection_playbooks(path, playbooks_to_import)) end end
playbooks_names()
click to toggle source
# File lib/smart_proxy_ansible/playbooks_reader.rb, line 6 def playbooks_names ReaderHelper.collections_paths.split(':').flat_map { |path| get_playbooks_names(path) } end
read_collection_playbooks(collections_path, playbooks_to_import = nil)
click to toggle source
# File lib/smart_proxy_ansible/playbooks_reader.rb, line 22 def read_collection_playbooks(collections_path, playbooks_to_import = nil) glob_path("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| name = ReaderHelper.playbook_or_role_full_name(path) { name: name, playbooks_content: File.read(path) } if playbooks_to_import.nil? || playbooks_to_import.include?(name) end.compact rescue Errno::ENOENT, Errno::EACCES => e message = "Could not read Ansible playbooks #{collections_path} - #{e.message}" raise ReadPlaybooksException, message end
Private Class Methods
glob_path(path)
click to toggle source
# File lib/smart_proxy_ansible/playbooks_reader.rb, line 37 def glob_path(path) Dir.glob path end