-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Group variables missing from hostvars #31755
Comments
This does not happen on 2.4.0. I run this playbook against a host in my infrastructure using 2.4.0 and 2.4.1: - hosts: some_host
tasks:
- debug: msg="{{ hostvars[inventory_hostname].keys() | length }}"
- debug: msg="{{ vars.keys() | length }}" Output on 2.4.0:
Output on 2.4.1:
|
ping @bcoca |
pinging @abadger possible regression from 2.4 -> v2.4.1.0-0.3.rc1 ? |
quick test, cannot reproduce:
i run in both 2.4. and 2.4.1 and get same:
|
@bcoca Could you try I just confirmed the behavior using your approach with my suggested difference, which confirms what you saw, and what I'm seeing. Following done with 2.4.1 rc3:
|
same results
and with your same ref:
just to make sure, using
|
When I reproduce your test more closely, I get the same result as you. The difference seems to be that the variable I'm accessing is not in the 'all' group, but in a different group the host is a member of.
platform_env: production
redis_version: 4.0.2 I get the same results as before, with this notable additional detail:
|
Using another group:
file used:
|
Discussed in IRC. This issue seems to only affect playbook-level variables. I've tried changing the Per @bcoca's request, here's a sanitized/simplified tree of what I'm working with:
|
So I cannot reproduce with play adjacent group_vars either, simple setup:
when i run:
|
@bcoca try specifying the inventory file in ansible.cfg.
Solution:
Where:
|
A simple use case to reproduce the problem: # group_vars/group/all.yml
---
key: value # inventories/test/inventory
[group]
localhost ansible_connection=local Result with ansible 2.4.0.0-1 $ ansible --inventory inventories/test/inventory all -m debug -a "var=key"
localhost | SUCCESS => {
"key": "value"
}
$ ansible --inventory inventories/test/inventory all -m debug -a "var=hostvars[inventory_hostname].key"
localhost | SUCCESS => {
"hostvars[inventory_hostname].key": "value"
} Result with ansible 2.4.1.0-1 $ ansible --inventory inventories/test/inventory all -m debug -a "var=key"
localhost | SUCCESS => {
"key": "value"
}
$ ansible --inventory inventories/test/inventory all -m debug -a "var=hostvars[inventory_hostname].key"
localhost | SUCCESS => {
"hostvars[inventory_hostname].key": "VARIABLE IS NOT DEFINED!"
}
# Same result whatever the value of ANSIBLE_PLAYBOOK_VARS_ROOT If you move the |
A The difference is that the |
see if this fixes it #32269 |
I confirm it fixes my use case. |
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
Installed from
v2.4.1.0-0.3.rc1
CONFIGURATION
OS / ENVIRONMENT
macOS sierra
SUMMARY
Variables defined in group_vars do not appear in hostvars for dynamic inventories.
STEPS TO REPRODUCE
some_var
in group_vars/some_grouphostvars['some_host']['some_var']
EXPECTED RESULTS
Variable is accessible in hostvars.
ACTUAL RESULTS
Variable is missing from hostvars.
The text was updated successfully, but these errors were encountered: