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: Ansible 1.9.5-1 does not load group or host variables #15093

Closed
nikut opened this issue Mar 22, 2016 · 11 comments
Closed

Regression: Ansible 1.9.5-1 does not load group or host variables #15093

nikut opened this issue Mar 22, 2016 · 11 comments
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Milestone

Comments

@nikut
Copy link
Contributor

nikut commented Mar 22, 2016

Issue Type:
  • Bug Report
Ansible Version:
ansible 1.9.5 (detached HEAD cdfbc4243a) last updated 2016/03/22 13:00:45 (GMT +300)
  lib/ansible/modules/core: (detached HEAD 44f55986d8) last updated 2016/03/22 13:03:25 (GMT +300)
  lib/ansible/modules/extras: (detached HEAD 114b70dba0) last updated 2016/03/22 13:03:28 (GMT +300)
Ansible Configuration:

Default

Environment:

Control host CentOS 5.11 or OS X 10.11.3, managed host is not relevant

Summary:

Ansible 1.9.5-1 does not load group or host variables from the inventory at all. This is a regression from 1.9.4-1.

Steps To Reproduce:

This is a synthetic test case but the same occurs in our production environment with normal playbooks and with all hosts causing massive breakage.

inventory/hosts:

[test]
localhost

inventory/group_vars/all:


---
test_var_all: "This is defined in inventory/group_vars/all"

inventory/group_vars/test:


---
test_var_test: "This is defined in inventory/group_vars/test"

inventory/host_vars/localhost:


---
test_var_localhost: "This is defined in inventory/host_vars/localhost"
Expected Results:

On 1.9.4-1:

nikut@s1977:~/ansible$ ansible -i inventory test -m debug -a var="hostvars['localhost']"
localhost | success >> {
    "var": {
        "hostvars['localhost']": {
            "group_names": [
                "test"
            ],
            "inventory_hostname": "localhost",
            "inventory_hostname_short": "localhost",
            "test_var_all": "This is defined in inventory/group_vars/all",
            "test_var_localhost": "This is defined in inventory/host_vars/localhost",
            "test_var_test": "This is defined in inventory/group_vars/test"
        }
    }
}
Actual Results:

On 1.9.5-1:

nikut@s1977:~/ansible$ ansible -i inventory test -m debug -a var="hostvars['localhost']"
localhost | success >> {
    "var": {
        "hostvars['localhost']": {
            "group_names": [
                "test"
            ],
            "inventory_hostname": "localhost",
            "inventory_hostname_short": "localhost"
        }
    }
}

@jpalomaki
Copy link

We also ran into this (ansible not loading variables in /path/to/inventory/group_vars/foo/main.yml) and had to revert to 1.9.4. This sort of thing should really be part of ansible's release testing.

@nikut
Copy link
Contributor Author

nikut commented Mar 23, 2016

Agreed, this is an absolute showstopper. Frankly I'm a little shocked that this kind of thing can get through unnoticed, it does not say good things about the release testing process. Also disappointing to see no activity on an issue like this for 17 hours.

@jbouzekri
Copy link

Same on 2.0.1.0 : #14945.

@nikut : you say 17h. Try more than 10 days ...

Sad. It has blocked the development of my team deployment tasks.

@abadger
Copy link
Contributor

abadger commented Mar 23, 2016

As a temporary workaround, if you are able to reference the hosts file directly instead of referencing the directory that it is inside of, then it will work. Figuring out what the difference between those two cases is now.

$ ansible-playbook 15093.yml -i inventory/hosts       (10:45:34)

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

TASK: [debug ] **************************************************************** 
ok: [localhost] => {
    "var": {
        "hostvars['localhost']": {
            "group_names": [
                "test"
            ],
            "inventory_hostname": "localhost",
            "inventory_hostname_short": "localhost",
            "test_var_all": "This is defined in inventory/group_vars/all",
            "test_var_in_hosts_file": "defined in hosts file",
            "test_var_localhost": "This is defined in inventory/host_vars/localhost",
            "test_var_test": "This is defined in inventory/group_vars/test"
        }
    }
}

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

@jimi-c jimi-c added bug_report P2 Priority 2 - Issue Blocks Release labels Mar 23, 2016
@jimi-c jimi-c added this to the stable-1.9 milestone Mar 23, 2016
@abadger
Copy link
Contributor

abadger commented Mar 23, 2016

git bisected to this commit: ab18fd2

EDIT: pasted the wrong hash. This is the problem commit: e856ac2

@abadger
Copy link
Contributor

abadger commented Mar 23, 2016

@jbouzekri I just checked and this bug is not present on 2.0.1.0 or devel. So looks like these are separate bugs.

@jbouzekri
Copy link

@abadger : but look at the referenced bug report #14945. It seems it is almost the same issue no ?

@abadger
Copy link
Contributor

abadger commented Mar 23, 2016

After comparing current code in stable-1.9 to code in devel I think that commit e856ac2 is wrong. The limit bug that was intended to fix is because something is not looking at runner.basedir (the equivalent of 2.x's vars['playbook_dir']). e856ac2 is modifying the basedir found for inventory rather than the one found for playbooks so it is doing the wrong thing. I'm going to revert that now in stable-1.9 and then look for where the runner.basedir is being omitted when limit is given.

abadger added a commit that referenced this issue Mar 23, 2016
This reverts commit e856ac2.

That commit was intended to fix --limit not honoring the playbook
directory as a source of inventory variable information.  However, the
commit changes the inventory basedir to where it thinks the playbook
basedir which breaks finding inventory variables inside of inventory
directories #15093.  Reverting this and looking for where limit might be
affecting the playbook basedir rather than the inventory basedir.
@abadger
Copy link
Contributor

abadger commented Mar 23, 2016

Okay, this should be fixed by the revert in 81c4817 and that problem with the --limit should be fixed by #13556. So I'm closing this bug as fixed.

@abadger abadger closed this as completed Mar 23, 2016
@nikut
Copy link
Contributor Author

nikut commented Mar 24, 2016

@abadger Confirmed that it works now in stable-1.9, both with my test case and with our production inventory. Thank you!

Hope there will be a test case for the "inventory is directory" case from now on. Will you be making a bugfix release considering the showstopper nature of this bug?

@abadger
Copy link
Contributor

abadger commented Apr 4, 2016

@nikut yes, there will be a 1.9.6... We're looking at one more bug on the 1.9 release and then we'll be putting out a release candidate.

If you'd like to make a pull request for an integration test of inventory is directory, that would be a great way for us to expand test coverage of this. Integration tests are ansible playbooks that use the assert module to show that the test conditions are met. They live here: https://github.com/ansible/ansible/tree/devel/test/integration

@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

6 participants