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

Bug when combining vars_files from main playbook and included playbooks #7596

Closed
kilburn opened this issue May 30, 2014 · 2 comments · Fixed by #7597
Closed

Bug when combining vars_files from main playbook and included playbooks #7596

kilburn opened this issue May 30, 2014 · 2 comments · Fixed by #7597
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release

Comments

@kilburn
Copy link
Contributor

kilburn commented May 30, 2014

Issue Type:

Bug Report

Ansible Version:

ansible 1.7 (devel 188ab7b) last updated 2014/05/30 06:53:46 (GMT +200)

Environment:

OS X Mavericks host - Debian wheezy guests (but this should be irrelevant)

Summary:

I have a playbook which uses vars_files to load some variables. Then it includes another playbook which uses "conditional imports" (http://docs.ansible.com/playbooks_variables.html#conditional-imports) to load more variables from external files. Ansible fails when trying to combine both these vars_files definitions with a TypeError: unhashable type: 'list'.

Steps To Reproduce:

Create empty files vars/default, vars/a, and vars/b. Then define this two playbooks:
play.yml:


---
- hosts: all
  vars_files: 
    - vars/default
- include: play-included.yml

play-included.yml:


---
- hosts: all
  vars_files: 
    - [ "vars/a", "vars/b" ]
  tasks:
    - fail: msg="This is actually success."

Now try to run playbook.yml with ansible-playbook and you get the error.

Expected Results:

Something like the following:

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [web.dev.local]

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [web.dev.local]

TASK: [fail msg="This is actually success."] ********************************** 
failed: [web.dev.local] => {"failed": true}
msg: This is actually success.

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/Users/marc/play.retry

web.dev.local              : ok=2    changed=0    unreachable=0    failed=1   
Actual Results:

Ansible fails with the following error:

Traceback (most recent call last):
  File "/Users/marc/Documents/Projects/ansible/ansible/bin/ansible-playbook", line 317, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/Users/marc/Documents/Projects/ansible/ansible/bin/ansible-playbook", line 200, in main
    force_handlers=options.force_handlers
  File "/Users/marc/Documents/Projects/ansible/ansible/lib/ansible/playbook/__init__.py", line 176, in __init__
    (self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook, vars)
  File "/Users/marc/Documents/Projects/ansible/ansible/lib/ansible/playbook/__init__.py", line 261, in _load_playbook_from_file
    p['vars_files'] = utils.list_union(p.get('vars_files', []), play_vars_files)
  File "/Users/marc/Documents/Projects/ansible/ansible/lib/ansible/utils/__init__.py", line 1014, in list_union
    set_a = set(_listify(a))
TypeError: unhashable type: 'list'
Reporter's comments:

The error is pretty clear in itself. The list_union function (introduced in 85bd681) is defined as:

def list_union(a, b):
    set_a = set(_listify(a))
    set_b = set(_listify(b))
    return list(set_a.union(set_b))

... but this is conceptually wrong. You cannot insert lists into sets because they are not hashable. Moreover, sets have no guaranteed order, so using set_union to combine lists may break the variable load ordering as intended by the user.

@mpdehaan
Copy link
Contributor

Tracebacks are bugs, regardless of cause. Will look at the linked PR.

@jimi-c
Copy link
Member

jimi-c commented Jun 3, 2014

The above PR was merged, and should resolve this issue. Please let us know if there are any further problems regarding this. Thanks!

jimi-c pushed a commit that referenced this issue Jun 9, 2014
Using sets for these operations is dangerous because sets cannot contain
certain object types (such as lists) and their iteration order is
undefined.

Fixes #7596
@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. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants