diff options
author | Sam Doran <sdoran@redhat.com> | 2019-06-28 16:19:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-28 16:19:27 -0400 |
commit | 6cf6f5a34bebe01f96782a171db8d83d4e7828ca (patch) | |
tree | 90eb9cb093c52d067bab0846ab91a4735d5fe253 /lib/ansible/config/manager.py | |
parent | 875e7c3e5036b1410e4170c4ff2589c3f12e5ac7 (diff) | |
download | ansible-6cf6f5a34bebe01f96782a171db8d83d4e7828ca.tar.gz |
Use atexit to cleanup tmp dirs (#56532)
* Wrap everything in try/except to avoid leaving files behind
* Add unit tests, integration tests, and changelog
* Do text the correct way
Diffstat (limited to 'lib/ansible/config/manager.py')
-rw-r--r-- | lib/ansible/config/manager.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index c951e82d58..15931e36d1 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -4,6 +4,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import atexit import io import os import os.path @@ -28,8 +29,7 @@ from ansible.module_utils._text import to_text, to_bytes, to_native from ansible.module_utils.parsing.convert_bool import boolean from ansible.parsing.quoting import unquote from ansible.utils import py3compat -from ansible.utils.path import unfrackpath -from ansible.utils.path import makedirs_safe +from ansible.utils.path import cleanup_tmp_file, makedirs_safe, unfrackpath Plugin = namedtuple('Plugin', 'name type') @@ -110,6 +110,7 @@ def ensure_type(value, value_type, origin=None): makedirs_safe(value, 0o700) prefix = 'ansible-local-%s' % os.getpid() value = tempfile.mkdtemp(prefix=prefix, dir=value) + atexit.register(cleanup_tmp_file, value, warn=True) elif value_type == 'pathspec': if isinstance(value, string_types): |