Class: Proxy::Ansible::PlaybooksReader
- Inherits:
-
Object
- Object
- Proxy::Ansible::PlaybooksReader
- Defined in:
- lib/smart_proxy_ansible/playbooks_reader.rb
Overview
Implements the logic needed to read the playbooks and associated information
Class Method Summary collapse
- .get_playbooks_names(collections_path) ⇒ Object
- .playbooks(playbooks_to_import) ⇒ Object
- .playbooks_names ⇒ Object
- .read_collection_playbooks(collections_path, playbooks_to_import = nil) ⇒ Object
Class Method Details
.get_playbooks_names(collections_path) ⇒ Object
16 17 18 19 20 |
# File 'lib/smart_proxy_ansible/playbooks_reader.rb', line 16 def get_playbooks_names(collections_path) Dir.glob("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| ReaderHelper.playbook_or_role_full_name(path) end end |
.playbooks(playbooks_to_import) ⇒ Object
10 11 12 13 14 |
# 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 ⇒ Object
6 7 8 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/smart_proxy_ansible/playbooks_reader.rb', line 22 def read_collection_playbooks(collections_path, playbooks_to_import = nil) Dir.glob("#{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 = "Could not read Ansible playbooks #{collections_path} - #{e.}" raise ReadPlaybooksException, end |