Add warnings for illegal file names in role (#81555)

Co-authored-by: Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
pull/81590/head
Aleksey Tsalolikhin 2 years ago committed by GitHub
parent 4ab5ecbe81
commit bdaa091b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
minor_changes:
- ansible-galaxy - used to crash out with a "Errno 20 Not a directory" error when extracting files from a role when hitting a file with an illegal name (https://github.com/ansible/ansible/pull/81553). Now it gives a warning identifying the culprit file and the rule violation (e.g., ``my$class.jar`` has a ``$`` in the name) before crashing out, giving the user a chance to remove the invalid file and try again. (https://github.com/ansible/ansible/pull/81555).
known_issues:
- ansible-galaxy - dies in the middle of installing a role when that role contains Java inner classes (files with $ in the file name). This is by design, to exclude temporary or backup files. (https://github.com/ansible/ansible/pull/81553).

@ -376,8 +376,20 @@ class GalaxyRole(object):
# It will create the parent directory as an empty file and will
# explode if the directory contains valid files.
# Leaving this as is since the whole module needs a rewrite.
if n_part != '..' and not n_part.startswith('~') and '$' not in n_part:
n_final_parts.append(n_part)
#
# Check if we have any files with illegal names,
# and display a warning if so. This could help users
# to debug a broken installation.
if n_part == '..':
display.warning(f"Illegal filename '{n_part}': '..' is not allowed")
continue
if n_part.startswith('~'):
display.warning(f"Illegal filename '{n_part}': names cannot start with '~'")
continue
if '$' in n_part:
display.warning(f"Illegal filename '{n_part}': names cannot contain '$'")
continue
n_final_parts.append(n_part)
member.name = os.path.join(*n_final_parts)
role_tar_file.extract(member, to_native(self.path))

@ -30,6 +30,11 @@
content: ""
dest: "{{ remote_tmp_dir }}/role.d/tasks/~invalid.yml"
- name: Invalid file
copy:
content: ""
dest: "{{ remote_tmp_dir }}/role.d/tasks/invalid$name.yml"
- name: Valid requirements file
copy:
dest: valid-requirements.yml

Loading…
Cancel
Save