galaxy: Handle empty roles and collections (#69199)

Galaxy collection install command raised indexError,
when requirements.yml contains empty roles and collections.

This fix handles empty roles and/or empty collections.

Fixes: #68186

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/69337/head
Abhijeet Kasurde 5 years ago committed by GitHub
parent 9d48884e36
commit 8d43d79191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Handle empty roles and empty collections in requirements.yml in ansible-galaxy install command (https://github.com/ansible/ansible/issues/68186).

@ -568,10 +568,10 @@ class GalaxyCLI(CLI):
raise AnsibleError("Expecting only 'roles' and/or 'collections' as base keys in the requirements "
"file. Found: %s" % (to_native(", ".join(extra_keys))))
for role_req in file_requirements.get('roles', []):
for role_req in file_requirements.get('roles') or []:
requirements['roles'] += parse_role_req(role_req)
for collection_req in file_requirements.get('collections', []):
for collection_req in file_requirements.get('collections') or []:
if isinstance(collection_req, dict):
req_name = collection_req.get('name', None)
if req_name is None:

@ -4,7 +4,7 @@
path: '{{ galaxy_dir }}/download'
state: directory
- name: download collection with multiple dependencides
- name: download collection with multiple dependencies
command: ansible-galaxy collection download parent_dep.parent_collection -s {{ fallaxy_galaxy_server }}
register: download_collection
args:
@ -86,3 +86,22 @@
- download_req_custom_path_actual.matched == 2
- (download_req_custom_path_actual.files[0].path | basename) in ['requirements.yml', 'namespace1-name1-1.1.0-beta.1.tar.gz']
- (download_req_custom_path_actual.files[1].path | basename) in ['requirements.yml', 'namespace1-name1-1.1.0-beta.1.tar.gz']
# https://github.com/ansible/ansible/issues/68186
- name: create test requirements file without roles and collections
copy:
content: |
collections:
roles:
dest: '{{ galaxy_dir }}/download/no_roles_no_collections.yml'
- name: install collection with requirements
command: ansible-galaxy collection install -r '{{ galaxy_dir }}/download/no_roles_no_collections.yml'
register: install_no_requirements
- name: assert install collection with no roles and no collections in requirements
assert:
that:
- '"Process install" in install_no_requirements.stdout'
- '"Starting collection" in install_no_requirements.stdout'

Loading…
Cancel
Save