diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2021-03-26 16:33:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-26 16:33:25 -0400 |
commit | 22330dd322634548e0f4d88aa9c5c017b7c04851 (patch) | |
tree | 7a3b3cfab7b5230afd806d093c0f7dadf459637f /lib/ansible/template | |
parent | 4a82e2c4860b88aa2d5ab2fd1f7cd79636005b5f (diff) | |
download | ansible-22330dd322634548e0f4d88aa9c5c017b7c04851.tar.gz |
Correctly set path and fullpath for template vars (#73924)
* Correctly set path and fullpath for template vars
don't expect path to always be full path
also added exception/tb on action fail
Diffstat (limited to 'lib/ansible/template')
-rw-r--r-- | lib/ansible/template/__init__.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index b694927ed9..3a51fef2ad 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -100,8 +100,13 @@ JINJA2_END_TOKENS = frozenset(('variable_end', 'block_end', 'comment_end', 'raw_ RANGE_TYPE = type(range(0)) -def generate_ansible_template_vars(path, dest_path=None): - b_path = to_bytes(path) +def generate_ansible_template_vars(path, fullpath=None, dest_path=None): + + if fullpath is None: + b_path = to_bytes(path) + else: + b_path = to_bytes(fullpath) + try: template_uid = pwd.getpwuid(os.stat(b_path).st_uid).pw_name except (KeyError, TypeError): @@ -112,11 +117,15 @@ def generate_ansible_template_vars(path, dest_path=None): 'template_path': path, 'template_mtime': datetime.datetime.fromtimestamp(os.path.getmtime(b_path)), 'template_uid': to_text(template_uid), - 'template_fullpath': os.path.abspath(path), 'template_run_date': datetime.datetime.now(), 'template_destpath': to_native(dest_path) if dest_path else None, } + if fullpath is None: + temp_vars['template_fullpath'] = os.path.abspath(path) + else: + temp_vars['template_fullpath'] = fullpath + managed_default = C.DEFAULT_MANAGED_STR managed_str = managed_default.format( host=temp_vars['template_host'], |