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

Fix group variable precedence in #6734 #9620

Closed
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
8 participants
@brian-brazil
Contributor

brian-brazil commented Nov 25, 2014

Group variables defined in inventory should override
entries in the group_vars directories.

Add regression test.

@abadger

This comment has been minimized.

Show comment
Hide comment
@abadger

abadger Nov 25, 2014

Member

Example behaviour from @brian-brazil 's comment on the other ticket:

I've discovered a regression in this change via git bisect, group_vars/all now overrides inventory file variables.

With an inventory of:

localhost

[all:vars]
a=bar

A site.yml of

---
- name: play
  hosts: all
  gather_facts: false
  tasks:
    - name: task
      debug: var=a

and a group_vars/all of

---
a: foo

make && ansible-playbook -i inv site.yml now has foo instead of bar.

Member

abadger commented Nov 25, 2014

Example behaviour from @brian-brazil 's comment on the other ticket:

I've discovered a regression in this change via git bisect, group_vars/all now overrides inventory file variables.

With an inventory of:

localhost

[all:vars]
a=bar

A site.yml of

---
- name: play
  hosts: all
  gather_facts: false
  tasks:
    - name: task
      debug: var=a

and a group_vars/all of

---
a: foo

make && ansible-playbook -i inv site.yml now has foo instead of bar.

@mpdehaan mpdehaan changed the title from Fix regression in #6734 to Fix group variable precedence in #6734 Nov 25, 2014

@maxim

This comment has been minimized.

Show comment
Hide comment
@maxim

maxim Jan 4, 2015

I suggest to bump priority to P1 since this is not only breaking things, but also a security issue, where secret variables (not begin overridden) could end up on servers where they don't belong.

maxim commented Jan 4, 2015

I suggest to bump priority to P1 since this is not only breaking things, but also a security issue, where secret variables (not begin overridden) could end up on servers where they don't belong.

Fix regression in #6734
Group variables defined in inventory should override
entries in the group_vars directories.

Add regression test.
@bcoca

This comment has been minimized.

Show comment
Hide comment
@bcoca

bcoca Apr 10, 2015

Member

actually we want group/host_vars to override inventory (and play group/host vars overriding inventory group/host vars).

Member

bcoca commented Apr 10, 2015

actually we want group/host_vars to override inventory (and play group/host vars overriding inventory group/host vars).

@brian-brazil

This comment has been minimized.

Show comment
Hide comment
@brian-brazil

brian-brazil Apr 11, 2015

Contributor

Can you explain why that is?

I have settings that are specific to a particular inventory file rather than any single group and I don't see a way around this regression for groups.

Contributor

brian-brazil commented Apr 11, 2015

Can you explain why that is?

I have settings that are specific to a particular inventory file rather than any single group and I don't see a way around this regression for groups.

@bcoca

This comment has been minimized.

Show comment
Hide comment
@bcoca

bcoca Apr 13, 2015

Member

I'm saying that this seems to be the intended way for this to work, the change looks to have been done to 'correct' the precedence to what it is now.

Member

bcoca commented Apr 13, 2015

I'm saying that this seems to be the intended way for this to work, the change looks to have been done to 'correct' the precedence to what it is now.

@brian-brazil

This comment has been minimized.

Show comment
Hide comment
@brian-brazil

brian-brazil Apr 13, 2015

Contributor

Hmm, my reading of the description of #6734 was that it was a refactor that shouldn't have affected behaviour - just performance.

@srvg Can you comment?

Contributor

brian-brazil commented Apr 13, 2015

Hmm, my reading of the description of #6734 was that it was a refactor that shouldn't have affected behaviour - just performance.

@srvg Can you comment?

@srgvg

This comment has been minimized.

Show comment
Hide comment
@srgvg

srgvg May 6, 2015

Member

Sorry, seems I missed my notification from this ticket.
AFAICR, I did not work explicitly on this precedence behaviour, in #6734

I'm not even sure what the right answer should be, as I normally never use variables in the ini file, and the ansible docs are not clear on precedence within inventory. I don't even think that was ever a well defined thing.

Either way, I can confirm this: if my refactoring changed this, it was not intended.

Member

srgvg commented May 6, 2015

Sorry, seems I missed my notification from this ticket.
AFAICR, I did not work explicitly on this precedence behaviour, in #6734

I'm not even sure what the right answer should be, as I normally never use variables in the ini file, and the ansible docs are not clear on precedence within inventory. I don't even think that was ever a well defined thing.

Either way, I can confirm this: if my refactoring changed this, it was not intended.

@brian-brazil

This comment has been minimized.

Show comment
Hide comment
@brian-brazil

brian-brazil May 6, 2015

Contributor

@srvg Thanks for the clarification.

@bcoca Given this behaviour was unintended, can this change be merged to fix the regression?

Contributor

brian-brazil commented May 6, 2015

@srvg Thanks for the clarification.

@bcoca Given this behaviour was unintended, can this change be merged to fix the regression?

@srgvg

This comment has been minimized.

Show comment
Hide comment
@srgvg

srgvg May 6, 2015

Member

If I'm not mistaken, I suspect this patch will also change the precedence between vars from a dynamic inventory script, and (group/host_vars and vars_plugins).

Perhaps we first should have a broader discussion on how precedence within the inventory should happen.

Member

srgvg commented May 6, 2015

If I'm not mistaken, I suspect this patch will also change the precedence between vars from a dynamic inventory script, and (group/host_vars and vars_plugins).

Perhaps we first should have a broader discussion on how precedence within the inventory should happen.

@amenonsen

This comment has been minimized.

Show comment
Hide comment
@amenonsen

amenonsen Jul 21, 2015

Contributor

In reviewing this change, I thought playbooks_variables.rst now clearly documented whether group_vars overrides group variables defined in the inventory, but somewhat to my surprise it does not. I can live with either behaviour (with a slight preference for status quo, i.e. things in the inventory are overriden by group_vars), but I really think it should be documented first, and then this PR accepted or rejected once and for all. It's a legitimate source of confusion otherwise.

Contributor

amenonsen commented Jul 21, 2015

In reviewing this change, I thought playbooks_variables.rst now clearly documented whether group_vars overrides group variables defined in the inventory, but somewhat to my surprise it does not. I can live with either behaviour (with a slight preference for status quo, i.e. things in the inventory are overriden by group_vars), but I really think it should be documented first, and then this PR accepted or rejected once and for all. It's a legitimate source of confusion otherwise.

@jimi-c

This comment has been minimized.

Show comment
Hide comment
@jimi-c

jimi-c Jun 6, 2016

Member

Looking back at this issue, it appears we have corrected it in devel (though it is still broken in stable-2.1, so it appears to be a recent fix).

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

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

PLAY [play] ********************************************************************

TASK [task] ********************************************************************
task path: /root/testing/9620/test.yml:6
ok: [localhost] => {
    "a": "bar"
}

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

As such, we're going to go ahead and close this now (and I'll ensure the fix ends up in stable-2.1 before the next release as well).

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!

Member

jimi-c commented Jun 6, 2016

Looking back at this issue, it appears we have corrected it in devel (though it is still broken in stable-2.1, so it appears to be a recent fix).

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

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

PLAY [play] ********************************************************************

TASK [task] ********************************************************************
task path: /root/testing/9620/test.yml:6
ok: [localhost] => {
    "a": "bar"
}

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

As such, we're going to go ahead and close this now (and I'll ensure the fix ends up in stable-2.1 before the next release as well).

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!

@jimi-c jimi-c closed this Jun 6, 2016

@jimi-c

This comment has been minimized.

Show comment
Hide comment
@jimi-c

jimi-c Jun 6, 2016

Member

Cherry picked fixes to stable-2.1 as well:

# ansible --version
ansible 2.1.0.0 (stable-2.1 9936d7355c) last updated 2016/06/06 14:57:59 (GMT -500)
  lib/ansible/modules/core: (detached HEAD bc0bc7a027) last updated 2016/06/06 14:47:41 (GMT -500)
  lib/ansible/modules/extras: (detached HEAD 891928b8d2) last updated 2016/06/06 14:47:41 (GMT -500)
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible']

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

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

PLAY [play] ********************************************************************

TASK [task] ********************************************************************
task path: /root/testing/9620/test.yml:6
ok: [localhost] => {
    "a": "bar"
}

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

jimi-c commented Jun 6, 2016

Cherry picked fixes to stable-2.1 as well:

# ansible --version
ansible 2.1.0.0 (stable-2.1 9936d7355c) last updated 2016/06/06 14:57:59 (GMT -500)
  lib/ansible/modules/core: (detached HEAD bc0bc7a027) last updated 2016/06/06 14:47:41 (GMT -500)
  lib/ansible/modules/extras: (detached HEAD 891928b8d2) last updated 2016/06/06 14:47:41 (GMT -500)
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible']

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

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

PLAY [play] ********************************************************************

TASK [task] ********************************************************************
task path: /root/testing/9620/test.yml:6
ok: [localhost] => {
    "a": "bar"
}

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

@ansibot ansibot added bug and removed bugfix_pull_request labels Mar 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment