-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Host variables adjacent to master playbook are unavailable to included tasks #32936
Comments
We're not sure this is a bug, and we don't mean for this to be confrontational. Let's explain what we're thinking:
If you need variables to be included adjacent to included playbooks in Ansible < 2.4.1, use As such, we're going to close this ticket. However, we're open to being corrected, should you wish to discuss. You can stop by one of our two mailing lists or IRC to talk about this and we might be persuaded otherwise.
Thank you once again for this and your interest in Ansible! |
I have the same problem with my playbooks with ansible 2.4.1. I think this is not related to tasks but to included playbooks from another directory (as group/host vars are loaded with every included/imported playbook - so the another_directory is the problem). The PLAYBOOK_VARS_ROOT config doesn't change anything (it's only task related not playbook related). Shortly >=2.4.0 breaks the backward compatibility for including playbooks (maybe the caption of this issue should be changed also). The workaround for this (on linux) is to symlink the group_vars and host_vars directories to every directory which contains included playbook otherwise you loose all group and host variables in the included playbook. The workaround for the example is: I see the point with vars_files or include_vars but it's weird to load all group and host vars via those features, isn't it? BTW the use case could even be more simplified and a little bit more descriptive.
|
You're correct. As you pointed out, using See this comment for further details on how variables are handled with |
ISSUE TYPE
COMPONENT NAME
Core
ANSIBLE VERSION
Note that this happens on 2.4.1.0 as well, which is the version I first had the issue with:
CONFIGURATION
DEFAULT_GATHERING(/home/ashka/.ansible.cfg) = implicit
DEFAULT_HOST_LIST(/home/ashka/.ansible.cfg) = ['/home/ashka/.ansible/hosts']
DEFAULT_MODULE_PATH(env: ANSIBLE_LIBRARY) = ['/home/ashka/build/ansible/library']
OS / ENVIRONMENT
N/A
SUMMARY
When including tasks that are included in an included playbook, and when the included playbook is not in the same directory as the master playbook, the host vars contained in a folder named
host_vars
that is adjacent to the master playbook are not available in the tasks file. This happens usingimport_tasks
as well asinclude_tasks
.STEPS TO REPRODUCE
playbook.yml
with the following content:a
folder and theincluded.yml
to include inside thea
folder:a
folder, create ab
folder and add atasks.yml
file inside:EXPECTED RESULTS
Variable is defined and its value is displayed. This used to be the case in 2.3 using
include
. As far as I have tested, the same behavior is observed when usedinclude
.ACTUAL RESULTS
Variable is not defined.
When moving
a/included.yml
in the same folder asplaybook.yml
and editingplaybook.yml
to includeincluded.yml
, then editingincluded.yml
to includea/b/tasks.yml
, the variable is defined:The text was updated successfully, but these errors were encountered: