Skip to content

Commit

Permalink
Revert ansible#39365, improve error messaging (ansible#41208)
Browse files Browse the repository at this point in the history
* Revert " Update TaskInclude _raw_params with the expanded/templated path to file (ansible#39365)"

This reverts commit 4b01b92.

* Improve error messaging, catch error templating parent path

(cherry picked from commit c403f01)
  • Loading branch information
sivel committed Jun 7, 2018
1 parent db3a3dd commit 72b1808
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
20 changes: 16 additions & 4 deletions lib/ansible/playbook/helpers.py
Expand Up @@ -189,7 +189,19 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
if not isinstance(parent_include, TaskInclude):
parent_include = parent_include._parent
continue
parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params')))
try:
parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params')))
except AnsibleUndefinedVariable as e:
if not parent_include.statically_loaded:
raise AnsibleParserError(
"Error when evaluating variable in dynamic parent include path: %s. "
"When using static imports, the parent dynamic include cannot utilize host facts "
"or variables from inventory" % parent_include.args.get('_raw_params'),
obj=task_ds,
suppress_extended_error=True,
orig_exc=e
)
raise
if cumulative_path is None:
cumulative_path = parent_include_dir
elif not os.path.isabs(cumulative_path):
Expand All @@ -212,9 +224,9 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
include_target = templar.template(t.args['_raw_params'])
except AnsibleUndefinedVariable as e:
raise AnsibleParserError(
"Error when evaluating variable in include name: %s.\n\n"
"When using static includes, ensure that any variables used in their names are defined in vars/vars_files\n"
"or extra-vars passed in from the command line. Static includes cannot use variables from inventory\n"
"Error when evaluating variable in import path: %s.\n\n"
"When using static imports, ensure that any variables used in their names are defined in vars/vars_files\n"
"or extra-vars passed in from the command line. Static imports cannot use variables from facts or inventory\n"
"sources like group or host vars." % t.args['_raw_params'],
obj=task_ds,
suppress_extended_error=True,
Expand Down
2 changes: 0 additions & 2 deletions lib/ansible/playbook/included_file.py
Expand Up @@ -144,8 +144,6 @@ def process_include_results(results, iterator, loader, variable_manager):
include_file = loader.path_dwim(include_result['include'])

include_file = templar.template(include_file)
# Update the task args to reflect the expanded/templated path
original_task.args['_raw_params'] = include_file
inc_file = IncludedFile(include_file, include_variables, original_task)
else:
# template the included role's name here
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions test/integration/targets/include_import/runme.sh
Expand Up @@ -63,7 +63,3 @@ ANSIBLE_STRATEGY='linear' ansible-playbook test_grandparent_inheritance.yml -i .
# undefined_var
ANSIBLE_STRATEGY='linear' ansible-playbook undefined_var/playbook.yml -i ../../inventory "$@"
ANSIBLE_STRATEGY='free' ansible-playbook undefined_var/playbook.yml -i ../../inventory "$@"

# Include path inheritance using host var for include file path
ANSIBLE_STRATEGY='linear' ansible-playbook include_path_inheritance/playbook.yml -i ../../inventory "$@"
ANSIBLE_STRATEGY='free' ansible-playbook include_path_inheritance/playbook.yml -i ../../inventory "$@"

0 comments on commit 72b1808

Please sign in to comment.