diff --git a/.ansible-lint b/.ansible-lint index 92478d5e18..30affe3883 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -38,6 +38,7 @@ skip_list: - meta-no-info - package-latest - fqcn-builtins + - no-jinja-when ################## # Tags to follow # diff --git a/ansible/playbooks/filter_plugins/container.py b/ansible/playbooks/filter_plugins/container.py new file mode 100644 index 0000000000..8aaae8d8a4 --- /dev/null +++ b/ansible/playbooks/filter_plugins/container.py @@ -0,0 +1,27 @@ +from typing import Any, Dict, List + + +class FilterModule: + """ Filters for Python's container types """ + + def filters(self): + return { + 'dict_to_list': self.dict_to_list + } + + def dict_to_list(self, data: Dict, only_values: bool = False, only_keys: bool = False) -> List: + """ + Convert dict to list without using Ansible's loop mechanism with dict2items filter. + + :param data: to be converted into a list + :param only_values: construct list with only dict's values + :param only_keys: construct list with only dict's keys + :return: data transformed into a list + """ + if only_values: + return list(data.values()) + + if only_keys: + return list(data.keys()) + + return list(data.items()) diff --git a/ansible/playbooks/repository.yml b/ansible/playbooks/repository.yml index b76cdda5fb..7a7a5e55a4 100644 --- a/ansible/playbooks/repository.yml +++ b/ansible/playbooks/repository.yml @@ -1,5 +1,5 @@ --- -# This playbook is empty by purpose, just to enable repository role in configuration/feature-mapping +# This playbook is empty by purpose, just to enable repository role in configuration/features # to populate defaults/configuration to Ansible vars - hosts: "!all" tasks: [] diff --git a/ansible/playbooks/roles/download/tasks/list_files.yml b/ansible/playbooks/roles/download/tasks/list_files.yml index 270fe93070..987e5adc52 100644 --- a/ansible/playbooks/roles/download/tasks/list_files.yml +++ b/ansible/playbooks/roles/download/tasks/list_files.yml @@ -1,25 +1,9 @@ --- -- name: Get file listing - uri: - method: GET - url: "{{ repository_url }}/files/?F=0" # F=0 formats the listing as a simple list (not FancyIndexed) - body_format: raw - return_content: true - validate_certs: "{{ validate_certs | default(false, true) | bool }}" # handling "undefined", "null", "empty" and "boolean" values all at once - register: uri_list_files - until: uri_list_files is success - retries: 3 - delay: 2 - become: false +- name: Get files list from the repository + include_tasks: list_requirements.yml + vars: + _requirements: files -# TODO: make it work with yaml or json (instead of html, sic!). -- name: Parse html response and return file listing +- name: Set files in repository as fact set_fact: - list_files_result: >- - {{ lines | select('match', regexp) - | reject('match', '.*Parent Directory.*') - | map('regex_replace', regexp, '\1') - | list }} - vars: - lines: "{{ uri_list_files.content.splitlines() }}" - regexp: '.*