New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors can be wrongly replaced on dynamically imported static include #34665
Comments
@johnboy2 Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. Here are the items we could not find in your description:
Please set the description of this issue with this template: |
!component +modules/utilities/logic/include_tasks.py |
!component +lib/ansible/modules/utilities/logic/include_tasks.py |
This actually has nothing to do with The problem is that, in order for a relatively pathed included file to be found, we look at the file of the parent include, to ensure we start with the correct directory. In this case, the path of the parent include is defined as When we try to template it in If we were to have defined !component -lib/ansible/plugins/callback/default.py |
A not so correct solution, but a solution nonetheless: diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py
index 248a840bb0..6518ace88f 100644
--- a/lib/ansible/playbook/helpers.py
+++ b/lib/ansible/playbook/helpers.py
@@ -178,7 +178,10 @@ 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:
+ parent_include_dir = ''
if cumulative_path is None:
cumulative_path = parent_include_dir
elif not os.path.isabs(cumulative_path): Ideally we would have to implement some form of path inheritance that didn't depend on host context. Which would mean every consolidated include result, would need a unique parent with vars pre-resolved for later. That isn't a fix that is simple, and not something that can make it into 2.6. The above fix just does the best we can, and assumes that the included file is immediately relative. |
Resolved in #39365 |
ISSUE TYPE
COMPONENT NAME
include_tasks
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Management node: Ubuntu 16.04
Remote node: Debian 9
SUMMARY
Untrue/incorrect error message shown when a dynamically-determined dynamic include contains an embedded reference to an unknown file.
STEPS TO REPRODUCE
test.yml:
Linux.yml:
Execute command:
EXPECTED RESULTS
The debug task should execute as expected, showing the remote system's platform (expected in this case to be "Linux").
For the "include_tasks" task, it should result in an error along the lines of:
(which is what you get with a straight-up static include of a missing file)
ACTUAL RESULTS
Debug task executes as expected (which also proves that
ansible_system
is defined).The "import_tasks" task fails, as expected, but does so with an entirely incorrect error message:
Ansible thus hides the actual fault in this case behind a completely false error.
The text was updated successfully, but these errors were encountered: