ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
62.92k stars 23.9k forks source link

Confusing group_vars, host_vars when using ip for hosts. #13809

Closed Incubatio closed 6 years ago

Incubatio commented 8 years ago

Issue Type: Feature and/or Bug Report

Ansible Version: ansible 1.9.3

Summary: In a host file, when defining two distinct groups pointing to the same ip, configuration get merged. I found this very unintuitive. However, when defining two groups pointing to two domain that point to the same ip group_vars and host vars will work as expected.

How to reproduce: https://github.com/Incubatio/ansible_variable_tests

Story: I'm a new ansible user. First docs tells us to define a group. Then docs tells us we can define group of groups. Then docs tells us we can define specific config for host and group.

My first personal conclusion was: "ok, a group is an entity for one or more hosts, so defining a group is like defining a virtual environment with the possibility to store variable inside it"

If I use ip address like this:

  ;HOSTS
  [apiservers]
  192.168.56.2 db_port=1111

  [gameservers]
  192.168.56.2 db_port=2222

the previous conclusion is incorrect, and db_port value will be 2222 regardless of the actual target group i'm deploying to.

If I use domain instead of ip like this:

  ;HOSTS
  [apiservers]
  a1.dev db_port=1111

  [gameservers]
  a2.dev db_port=2222

the previous conclusion is correct, and db_port value will be defined according to the group i'm deploying to.

EDIT: Sorry for the first post, it was long, poorly written and partly incorrect.

warvariuc commented 8 years ago

I found this very unintuitive.

Agreed. Too many such inconsistencies with Ansible's interface.

alvarogmj commented 8 years ago

Unintuitive, yes. I was recently bitten by a similar issue. However, it makes sense once you see how "hostvars" is laid out, host vars don't seem to be linked in any way to the groups on which they are defined. The documentation should make this point clearer.

stevesirois commented 8 years ago

I found this very unintuitive.

Must agree too! Reading the docs doesn't say a word about this and, for exemple, managing multiple instance of apache configuration make this behaviour very confusing and counter intuitive. If your using a --limit clause, you expect that the variable define in THAT groups_vars get picked up., NOT the other groups just because it's the same host!?

ansibot commented 7 years ago

@Incubatio Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

Please set the description of this issue with this template: https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

ansibotdev commented 6 years ago

@Incubatio You have not responded to information requests in this issue so we will assume it no longer affects you. If you are still interested in this, please create a new issue with the requested information.

click here for bot help

Incubatio commented 6 years ago

bot_broken

Incubatio commented 6 years ago

i'm not sure what is the component name (if there is one related to it). Is there a component list somewhere that i could check ?