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

include_role 'name' parameter overrides role variable #30776

Closed
duck-rh opened this Issue Sep 22, 2017 · 5 comments

Comments

Projects
None yet
6 participants
@duck-rh

duck-rh commented Sep 22, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

include_role

ANSIBLE VERSION
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/duck/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/duck/.local/lib/python2.7/site-packages/ansible
  executable location = /home/duck/.local/bin/ansible
  python version = 2.7.14 (default, Sep 17 2017, 18:50:44) [GCC 7.2.0]
CONFIGURATION

PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30

OS / ENVIRONMENT

The controller is running Debian unstable, the tested targets run Debian Stretch (also tested locally on the controller).

SUMMARY

Inside the role I'm using either a variable set in the play or a loop variable inside the role called name. The intended value is later replaced by the name of the role.

STEPS TO REPRODUCE

First example with a play variable.

Playbook:

---
- hosts: all
  vars:
    name: pouet
  tasks:
    - include_role:
        name: plop

roles/plop/tasks/main.yml:

---
- debug:
    var: name

Second example with a loop variable inside the role.

Playbook:

---
  - hosts: all
  tasks:
    - include_role:
        name: plop
      vars:
        stuff:
          a: 1
          b: 2
          c: 3

roles/plop/tasks/main.yml:

---
- template:
    src: z.j2
    dest: /tmp/z.txt

roles/plop/templates/z.j2:

{% for name, index in stuff.iteritems() %}
{% include "inc.j2" %}
{% endfor %}

roles/plop/templates/inc.j2:

hello {{ name }} your index is {{ index }}
EXPECTED RESULTS
ok: [localhost] => {
    "name": "pouet"
}
hello pouet your index is 1
hello pouet your index is 3
hello pouet your index is 2

This workes in the 2.3.x series.

ACTUAL RESULTS
ok: [localhost] => {
    "name": "plop"
}
hello plop your index is 1
hello plop your index is 3
hello plop your index is 2

This changed starting from 2.4.0. name being a parameter, not a variable in vars:, it should not impact. It is not a reserved variable according to the doc (I could have expected role_name to appear though).

@bcoca

This comment has been minimized.

Show comment
Hide comment
@bcoca

bcoca Sep 29, 2017

Member

fixed via #30954

Member

bcoca commented Sep 29, 2017

fixed via #30954

@bcoca bcoca closed this Sep 29, 2017

@duck-rh

This comment has been minimized.

Show comment
Hide comment
@duck-rh

duck-rh Oct 2, 2017

Thanks :-)

duck-rh commented Oct 2, 2017

Thanks :-)

@duck-rh

This comment has been minimized.

Show comment
Hide comment
@duck-rh

duck-rh Dec 26, 2017

@bcoca I can reproduce the problem with 2.4.2.0 and the same two cases, could you reopen?

duck-rh commented Dec 26, 2017

@bcoca I can reproduce the problem with 2.4.2.0 and the same two cases, could you reopen?

@duck-rh

This comment has been minimized.

Show comment
Hide comment
@duck-rh

duck-rh Dec 26, 2017

The patch went without a test :-/

duck-rh commented Dec 26, 2017

The patch went without a test :-/

@ansibot ansibot added bug and removed bug_report labels Mar 7, 2018

@hkariti

This comment has been minimized.

Show comment
Hide comment
@hkariti

hkariti Mar 13, 2018

Contributor

Can confirm this too, also on HEAD.

Contributor

hkariti commented Mar 13, 2018

Can confirm this too, also on HEAD.

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