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

variable conflict with 'role_name' value #6800

Closed
sean-abbott opened this issue Apr 1, 2014 · 4 comments
Closed

variable conflict with 'role_name' value #6800

sean-abbott opened this issue Apr 1, 2014 · 4 comments
Assignees
Labels
bug This issue/PR relates to a bug. P1 Priority 1 - Immediate Attention Required; Release Immediately After Fixed

Comments

@sean-abbott
Copy link

Issue Type:

Bug Report

Ansible Version:

1.4.5
1.5.3

Environment:

ubuntu 10.04, python 2.6.
Ansible installed via rquillo ppa
Ansible installed via git clone+hacking/setup.env

Summary:

double variable usage in play.py, with one clobbering the other

Steps To Reproduce:

Relevant roles here:
https://github.com/qkslvrwolf/ansible_roles
stack trace and error description here: http://pastebin.com/Vi1ujErt
snippet calling roles:

    ---
    - hosts: jenkins_slaves
      sudo: yes
      roles: 
        - { role: lunabuild_jenkins_slave_reference }
Expected Results:

The role will run

Actual Results:
Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 269, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/bin/ansible-playbook", line 169, in main
    play = ansible.playbook.Play(pb, play_ds, play_basedir)
  File "/home/seabbott/workspace/fresh_ansible_venv/lib/python2.6/site-packages/ansible/playbook/play.py", line 141, in __init__
    self._tasks      = self._load_tasks(self._ds.get('tasks', []), load_vars)
  File "/home/seabbott/workspace/fresh_ansible_venv/lib/python2.6/site-packages/ansible/playbook/play.py", line 550, in _load_tasks
    x['role_name'] = new_role
TypeError: 'str' object does not support item assignment
@mpdehaan
Copy link
Contributor

mpdehaan commented Apr 1, 2014

Can you please share a minimal example?

It sounds like you defined a variable named 'role_name', in which case this is reserved, and you shouldn't do this.

I would agree it might be nice that there is a warning about reserved variables, and there's a ticket open about this one.

Let us know.

@sean-abbott
Copy link
Author

In play.py (in versions 1.5.3 and 1.4.5):

In version 1.4.5:
430: for x in tasks:
537: for x in data:

In version 1.5.3:
503: for x in tasks:
590: for x in data:

The second x clobbers the first, as it is inside the loop.

This results in a TypeError, because the inner line attempts to reference x as a dictionary, but x has been assigned a a string key from data at that point.

I haven't quite been able to figure out what is being assigned where, yet

@mpdehaan mpdehaan changed the title play.py has a variable conflict variable conflict with 'role_name' value Apr 1, 2014
@sean-abbott
Copy link
Author

Ok, I took a stab at making a fairly simple example. You can create an inventory any test machine, and point this playbook at it.

https://github.com/qkslvrwolf/ansible_roles

You'll need ansible_error_test, level_1_role, level_2_role, and l2_includes_role.

Just change the role in the error.yml playbook depending on what you want to try. The level_1_role works, the level_2_role gives you on error (that clearly demostrates that x was overridden incorrectly), and and l2_includes show what happens when you have both role dependency and includes in a task main.yml

There's another little oddity. We have
for x in tasks
...
items = ['']
....
for item in items:

And items is never referenced between it assigning to a list with a single empty string and being used in a for loop.

@mpdehaan mpdehaan added P2 and removed P2 labels Apr 2, 2014
@jimi-c jimi-c self-assigned this Apr 2, 2014
@jimi-c jimi-c closed this as completed in a6a4680 Apr 2, 2014
@jimi-c
Copy link
Member

jimi-c commented Apr 2, 2014

The above patch should fix this issue, and will be included in the next major release. If you continue to have any problems regarding this issue, please let us know.

Regarding the "for item in items" issue, it does appear that the loop will only ever execute once, so could probably be removed. If you'd like to open a separate issue for that, please feel free to do so.

Thanks!

@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 24, 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. P1 Priority 1 - Immediate Attention Required; Release Immediately After Fixed
Projects
None yet
Development

No branches or pull requests

5 participants