IndexError in plugins/lookup/subelements.py after upgrade from 1.9 to 2.0

Upgrading from 1.9.5 to 2.0.1.0 without changing the playbook, a task fails that used to work.

The error:

[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error… This feature will be removed in a

future release. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

An exception occurred during task execution. The full traceback is:

Traceback (most recent call last):

File “/usr/local/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 89, in run

items = self._get_loop_items()

File “/usr/local/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 189, in _get_loop_items

items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader, templar=templar).run(terms=loop_terms, variables=self._job_vars)

File “/usr/local/lib/python2.7/site-packages/ansible/plugins/lookup/subelements.py”, line 37, in run

terms[0] = listify_lookup_plugin_terms(terms[0], templar=self._templar, loader=self._loader)

IndexError: list index out of range

fatal: [somehostname]: FAILED! => {“failed”: true, “msg”: “Unexpected failure during module execution.”, “stdout”: “”}

to retry, use: --limit @deploy.retry

PLAY RECAP *********************************************************************

somehostname : ok=4 changed=1 unreachable=0 failed=1

The task:

  • name: copy apt key files from all roles to /tmp
    become: no
    copy: src=“{{ item.1.path }}/{{ item.1.filename }}” dest=“/tmp/{{ item.1.filename }}”
    when: “‘{{ item.0.role }}’ in {{ role_names }} and ‘{{ item.1.pub }}’ not in ansible_local.installed_apt_keys.key_list”
    with_subelements:
  • ‘{{ apt_keys_by_role }}’
  • ‘{{ keyfiles }}’

The relevant variables:

apt_keys_by_role:

  • role: common
    keyfiles:
  • path: “{{ inventory_dir }}/roles/common/files/apt_keys”
    filename: linode.gpg
    pub: 325A043E
  • role: dev
    keyfiles:
  • path: “{{ inventory_dir }}/roles/dev/files/apt_keys”
    filename: nodesource.gpg.key
    pub: 68576280

Ideas about what I need to do to fix this for 2.0?

Bonus points: how do you use pdb with Ansible’s Python modules? I tried sticking import pdb; pdb.set_trace() before the line that produces the IndexError in /usr/local/lib/python2.7/site-packages/ansible/plugins/lookup/subelements.py, but that turns the error into a BdbQuit; the (pdb) prompt is printed but it insta-quits and keeps on going with the task.