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

v2: KeyError while looking up role of a handler in the role cache #12882

Closed
mgedmin opened this issue Oct 23, 2015 · 3 comments
Closed

v2: KeyError while looking up role of a handler in the role cache #12882

mgedmin opened this issue Oct 23, 2015 · 3 comments
Assignees
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@mgedmin
Copy link
Contributor

mgedmin commented Oct 23, 2015

I apologize for not having time to produce a good quality bug report. I'll come back later and polish it.

ansible 2.0.0 (devel 4fd4f3374a) last updated 2015/10/23 10:41:07 (GMT +300)
  lib/ansible/modules/core: (detached HEAD 3fa6626094) last updated 2015/10/23 10:41:27 (GMT +300)
  lib/ansible/modules/extras: (detached HEAD b65a583902) last updated 2015/10/23 10:41:27 (GMT +300)

My test playbook fails with this Ansible version (it worked a couple of days ago). The error is:

TASK [roundup : configure alias_maps] ******************************************
changed: [trusty] => {"changed": true, "invocation": {"module_args": {"name": "collectd", "state": "restarted"}, "module_name": "service"}, "name": "collectd", "state": "started"}
Unexpected Exception: u'common'
the full traceback was:

Traceback (most recent call last):
  File "/home/mg/src/ansible/bin/ansible-playbook", line 80, in <module>
    sys.exit(cli.run())
  File "/home/mg/src/ansible/lib/ansible/cli/playbook.py", line 142, in run
    results = pbex.run()
  File "/home/mg/src/ansible/lib/ansible/executor/playbook_executor.py", line 140, in run
    result = self._tqm.run(play=play)
  File "/home/mg/src/ansible/lib/ansible/executor/task_queue_manager.py", line 217, in run
    return strategy.run(iterator, play_context)
  File "/home/mg/src/ansible/lib/ansible/plugins/strategy/linear.py", line 203, in run
    self._execute_meta(task, play_context, iterator)
  File "/home/mg/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 565, in _execute_meta
    self.run_handlers(iterator, play_context)
  File "/home/mg/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 464, in run_handlers
    result = self._do_handler_run(handler, handler_name, iterator=iterator, play_context=play_context)
  File "/home/mg/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 489, in _do_handler_run
    host_results = self._wait_on_pending_results(iterator)
  File "/home/mg/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 305, in _wait_on_pending_results
    results = self._process_pending_results(iterator)
  File "/home/mg/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 219, in _process_pending_results
    for (entry, role_obj) in iteritems(iterator._play.ROLE_CACHE[task_result._task._role._role_name]):
KeyError: u'common'

I have two handlers with that name, in different roles:

$ git grep 'restart collectd'
roles/common/handlers/main.yml:- name: restart collectd
roles/common/tasks/collectd.yml:  notify: restart collectd
roles/common/tasks/collectd.yml:  notify: restart collectd
roles/common/tasks/collectd.yml:  notify: restart collectd
roles/eversheds/handlers/main.yml:- name: restart collectd
roles/eversheds/tasks/collectd.yml:  notify: restart collectd

My playbook includes all of the roles (including common, eversheds, and, as the last one, roundup).

Reproduction of this bug takes 15 minutes at the moment, and I haven't had the time to try and produce a smaller reproductor.

@jimi-c jimi-c added this to the v2 milestone Oct 23, 2015
@mgedmin
Copy link
Contributor Author

mgedmin commented Oct 26, 2015

Steps to Reproduce

Define two roles and a playbook:

  • roles/a/tasks/main.yml:
- name: do stuff for role a
  command: echo 'stuff for a'
  notify: unrelated
  • roles/a/handlers/main.yml:
- name: unrelated
  command: echo 'unrelated handler'

- name: restart collectd
  command: echo 'service collectd restart'
  • roles/b/tasks/main.yml:
- name: do stuff for role b
  command: echo stuff for b
  notify: restart collectd
  • roles/b/handlers/main.yml:
- name: restart collectd
  command: echo 'service collectd restart'
  • test.yml:
- hosts: localhost
  gather_facts: no
  roles:
    - a

- hosts: localhost
  gather_facts: no
  roles:
    - b

Now run ansible-playbook test.yml.

Expected Result

PLAY [localhost] ************************************************************** 

TASK: [a | do stuff for role a] *********************************************** 
changed: [localhost]

NOTIFIED: [a | unrelated] ***************************************************** 
changed: [localhost]

PLAY [localhost] ************************************************************** 

TASK: [b | do stuff for role b] *********************************************** 
changed: [localhost]

NOTIFIED: [b | restart collectd] ********************************************** 
changed: [localhost]

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

Actual Result

PLAY ***************************************************************************

TASK [a : do stuff for role a] *************************************************
changed: [localhost]

RUNNING HANDLER [a : unrelated] ************************************************
changed: [localhost]

PLAY ***************************************************************************

TASK [b : do stuff for role b] *************************************************
changed: [localhost]

RUNNING HANDLER [a : restart collectd] *****************************************
changed: [localhost]
Unexpected Exception: u'a'
to see the full traceback, use -vvv

@mgedmin
Copy link
Contributor Author

mgedmin commented Oct 26, 2015

git bisect blames commit a3e913d

@jimi-c
Copy link
Member

jimi-c commented Oct 26, 2015

Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next major release.

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!

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 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.
Projects
None yet
Development

No branches or pull requests

3 participants