-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add image-registry configuration reading (#3106)
- Loading branch information
Showing
22 changed files
with
1,215 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '.*<li><a href="([^"]+)".*' | ||
list_files_result: "{{ list_requirements_result }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Get images list from the repository | ||
include_tasks: list_requirements.yml | ||
vars: | ||
_requirements: images | ||
|
||
- name: Set images in repository as fact | ||
set_fact: | ||
list_images_result: "{{ list_requirements_result }}" |
25 changes: 25 additions & 0 deletions
25
ansible/playbooks/roles/download/tasks/list_requirements.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
- name: Get requirements listing | ||
uri: | ||
method: GET | ||
url: "{{ repository_url }}/{{ _requirements }}/?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 | ||
|
||
# TODO: make it work with yaml or json (instead of html, sic!). | ||
- name: Parse html response and return requirements listing | ||
set_fact: | ||
list_requirements_result: >- | ||
{{ lines | select('match', regexp) | ||
| reject('match', '.*Parent Directory.*') | ||
| map('regex_replace', regexp, '\1') | ||
| list }} | ||
vars: | ||
lines: "{{ uri_list_files.content.splitlines() }}" | ||
regexp: '.*<li><a href="([^"]+)".*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.