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

inventory option in config ignored #11907

Closed
udondan opened this issue Aug 10, 2015 · 6 comments
Closed

inventory option in config ignored #11907

udondan opened this issue Aug 10, 2015 · 6 comments
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@udondan
Copy link

udondan commented Aug 10, 2015

I just updated my Ansible clone from the master branch.

The inventory option in the ansible.cfg now is ignored.

[defaults]
inventory = ./inventory/default

ERROR! Unable to find an inventory file (/etc/ansible/ansible_hosts), specify one with -i ?

This used to work in all previous versions (since inventory was introduced as config option)

@bcoca bcoca added this to the v2 milestone Aug 10, 2015
@bcoca
Copy link
Member

bcoca commented Aug 13, 2015

i just tested this and it works for me, considering that "/etc/ansible/ansible_hosts" is not the default, could you have another entry or another ansible.cfg pointing at that?

if you run with -v ansible should show which ansible.cfg it is using.

@udondan
Copy link
Author

udondan commented Aug 13, 2015

Ansible is using the correct config file. I made sure other options are not ignored. it is only the option for the inventory.

udondan@myhost:~/ansible-test$ ansible --version
ansible 2.0.0
  config file = /Users/udondan/ansible-test/ansible.cfg
  configured module search path = None


udondan@myhost:~/ansible-test$ tree
.
├── ansible.cfg
├── inventory
│   └── local
└── playbook.yml

1 directories, 3 files


udondan@myhost:~/ansible-test$ cat ansible.cfg
[defaults]
inventory         = ./inventory/local


udondan@myhost:~/ansible-test$ cat inventory/local 
[local]
localhost


udondan@myhost:~/ansible-test$ ansible-playbook playbook.yml -vvv
Using /Users/udondan/ansible-test/ansible.cfg as config file
ERROR! Unable to find an inventory file (/etc/ansible/ansible_hosts), specify one with -i ?

I just pulled from devel branch before testing this again with commit c6733cc1a7546273cf8e0e940ec60c7c38761b67.

Now downgrading and running the same again:

udondan@myhost:~/ansible-test$ sudo rm -rf /usr/local/lib/python2.7/site-packages/ansible-2.0.0-py2.7.egg/


udondan@myhost:~/ansible-test$ sudo rm -rf /usr/local/bin/ansibl*


udondan@myhost:~/ansible-test$ brew install ansible
==> Downloading https://homebrew.bintray.com/bottles/ansible-1.9.2.yosemite.bottle.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/ansible-1.9.2.yosemite.bottle.2.tar.gz
==> Pouring ansible-1.9.2.yosemite.bottle.2.tar.gz
🍺  /usr/local/Cellar/ansible/1.9.2: 4748 files, 58M


udondan@myhost:~/ansible-test$ ansible --version
ansible 1.9.2
  configured module search path = None


udondan@myhost:~/ansible-test$ ansible-playbook playbook.yml

PLAY [Testing] **************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [localhost]

TASK: [debug msg="OK"] ******************************************************** 
ok: [localhost] => {
    "msg": "OK"
}

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

@amenonsen
Copy link
Contributor

Do you have ANSIBLE_HOSTS or ANSIBLE_INVENTORY set in your environment?

@udondan
Copy link
Author

udondan commented Aug 13, 2015

Indeed, ANSIBLE_HOSTS is set, ANSIBLE_INVENTORY is not. And that seems to have caused it.

I had this value in my .bashrc

export ANSIBLE_HOSTS=/etc/ansible/ansible_hosts

That was from when I first tried Ansible about 1,5 years ago and does not reflect my current setup. Removing the entry now solved the problem.

So it seems like the precedence has changed. In 1.9.x the settings in ansible.cfg relative to the playbook weighs more than the env ANSIBLE_HOSTS. In 2.x ANSIBLE_HOSTS overrides the value in ansible.cfg.

Is this change expected? I wasn't able to find a statement in the docs how the precedence actually should be.

I think it made more sense the way it used to be. When you have different projects you probably have an ansible.cfg in each root folder of the project. Those settings should be used. The environment makes sense as a fallback when nothing else is defined and you run an ad-hoc command with ansible on some hosts.

@bcoca
Copy link
Member

bcoca commented Aug 18, 2015

Its a mismatch, for backwards compatibility ansible_hosts has precedence over ansible_inventory, but it gets set to ANSIBLE_HOSTS which then makes ANSIBLE_HOSTS trump ansible_inventory unintentionally.

@bcoca
Copy link
Member

bcoca commented Aug 18, 2015

it was actually intended the other way around in but the switch to v2 messed with that code

@bcoca bcoca closed this as completed Aug 18, 2015
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 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.
Projects
None yet
Development

No branches or pull requests

4 participants