Skip to content
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

regression: host_vars in inventory_dir not considered #16117

Closed
benjixx opened this issue Jun 3, 2016 · 10 comments
Closed

regression: host_vars in inventory_dir not considered #16117

benjixx opened this issue Jun 3, 2016 · 10 comments
Assignees
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release

Comments

@benjixx
Copy link
Contributor

benjixx commented Jun 3, 2016

ISSUE TYPE

Bug Report

ANSIBLE VERSION

ansible@devel (commit 273a965 specifically)

CONFIGURATION

N/A

OS / ENVIRONMENT

MacOS 10.11.5

SUMMARY

The issue I reported in #12742 (which had been fixed) popped up again this morning. Turns out that the responsible commit is 273a965.

I discovered this as one of my nightly builds that runs against ansible@devel failed: https://travis-ci.org/goodplay/goodplay/jobs/134945180

STEPS TO REPRODUCE

see #12742

EXPECTED RESULTS

see #12742

ACTUAL RESULTS

see #12742

@bcoca bcoca added the P2 Priority 2 - Issue Blocks Release label Jun 3, 2016
@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2016

@benjixx when I re-run the reproducer I had in #12742, I see the correct output:

# ansible-playbook -vv playbooks/test.yml -i inventory/
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: test.yml *************************************************************
1 plays in playbooks/test.yml

PLAY [localhost] ***************************************************************

TASK [debug] *******************************************************************
task path: /root/testing/12742/mytest/playbooks/test.yml:5
ok: [localhost] => {
    "inventory_group_var": "inventory group var"
}

TASK [debug] *******************************************************************
task path: /root/testing/12742/mytest/playbooks/test.yml:6
ok: [localhost] => {
    "inventory_host_var": "inventory host var"
}

TASK [debug] *******************************************************************
task path: /root/testing/12742/mytest/playbooks/test.yml:7
ok: [localhost] => {
    "playbook_group_var": "playbook group var"
}

TASK [debug] *******************************************************************
task path: /root/testing/12742/mytest/playbooks/test.yml:8
ok: [localhost] => {
    "playbook_host_var": "playbook host var"
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0   

Can you share exactly how your test reproduces the problem you're seeing?

@jimi-c jimi-c added the needs_info This issue requires further information. Please answer any outstanding questions. label Jun 5, 2016
@benjixx
Copy link
Contributor Author

benjixx commented Jun 5, 2016

@jimi-c I just tried with your reproducer from #12742 in the same way you did, and it seems: you're right. This works.

But there are strange things going on here. By just slightly changing your example the problem appears again:

cat ./inventory/group_vars/all
inventory_group_var: "inventory group var"

cat ./inventory/host_vars/localhost
inventory_host_var: "inventory host var"

cat ./inventory/inv
localhost ansible_connection=local

cat ./playbooks/test.yml
---
- hosts: localhost
  gather_facts: no
  tasks:
  - debug: var=inventory_group_var
  - debug: var=inventory_host_var

ansible-playbook -i inventory/ playbooks/test.yml
PLAY [localhost] ***************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
    "inventory_group_var": "inventory group var"
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "inventory_host_var": "VARIABLE IS NOT DEFINED!"
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0

Do you have any clue what's happening here?

@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2016

This did bisect down to 273a965, so I'll look into why.

@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2016

So it looks like this is because I stopped it from saving the host_vars locally in the hosts .vars dictionary locally, but we're not properly finding the path from the inventory for the host_vars file.

@jimi-c
Copy link
Member

jimi-c commented Jun 6, 2016

I believe I have this fixed, however I want to add some unit tests to make sure we don't run into this again.

@jimi-c jimi-c removed the needs_info This issue requires further information. Please answer any outstanding questions. label Jun 6, 2016
jimi-c added a commit that referenced this issue Jun 6, 2016
Also fixes a bug where add_host was not adding the vars files

Fixes #16117
@jimi-c jimi-c closed this as completed in 560532d Jun 6, 2016
@jimi-c
Copy link
Member

jimi-c commented Jun 6, 2016

Due to the nature of this bug and the structure of the unit tests, I've been unable to exactly recreate the way this bug occurs, so for now I've just merged in the above patch to fix this. Unfortunately the inventory code is overdue for some cleanups and refactoring (it's the only major chunk of code that wasn't changed much in 2.0+), and as such doesn't have very good unit tests. We'll be addressing that in the future.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@alikins
Copy link
Contributor

alikins commented Jun 6, 2016

is #16128 related?

@jimi-c
Copy link
Member

jimi-c commented Jun 6, 2016

Yep, and should now be fixed too.

@benjixx
Copy link
Contributor Author

benjixx commented Jun 6, 2016

Latest ansible@devel currently makes my build green again. Thanks @jimi-c. Much appreciated.

@jimi-c
Copy link
Member

jimi-c commented Jun 6, 2016

@benjixx excellent, thanks for the follow up!

jimi-c added a commit that referenced this issue Jun 6, 2016
Also fixes a bug where add_host was not adding the vars files

Fixes #16117
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

No branches or pull requests

5 participants