Correct usage for shutil.rmtree (#31541)

* Correct usage for shutil.rmtree

Fix adds correct usage of shutil.rmtree in git module

Fixes: #31225

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>

* Include archive tests so they get run

* Use new include syntax

* Cleanup syntax on git tests

- use multi-line YAML
- remove unneeded {{ }} around vars in conditionals
- remove unneeded quotes
- add task file name to task names for easier troubleshooting when things fail

* Make archive tests work for RHEL/CentOS 6

The older versions of Jinja2 in RHEL/CentOS 6 required assertion tasks using the map filter to be skipped.

The older version of git required gzip compression to be skipped on RHEL/CentOS 6.

* Account for ansible_distribution_major_version missing
This commit is contained in:
Abhijeet Kasurde 2017-10-13 20:00:15 +05:30 committed by Sam Doran
parent 42deaf2c71
commit a047fe0e4c
18 changed files with 385 additions and 314 deletions

View file

@ -942,13 +942,13 @@ def create_archive(git_path, module, dest, archive, version, repo, result):
result.update(changed=False)
# Cleanup before exiting
try:
shutil.remove(tempdir)
shutil.rmtree(tempdir)
except OSError:
pass
else:
try:
shutil.move(new_archive, archive)
shutil.remove(tempdir)
shutil.rmtree(tempdir)
result.update(changed=True)
except OSError as e:
module.fail_json(msg="Failed to move %s to %s" %