with_items and default filter with empty list not working in ansible 1.8.1

Hello guys,

I’ve recently updated ansible to v1.8.1 and I’m having some issues with some playbooks that worked on older ansible versions.

For example I’ve a reusable role that manages the installation of packages with the following task:

  • name: Install additional packages
    apt: name={{ item }} update_cache=yes
    with_items: additional_packages|default()

Where the variable additional_packages is usually not defined, but can be set on a per host or per group base.
On older versions this worked as expected:

  • if additional_packages is not defined, default to an empty list and skip the task
  • if additional_packages is defined, install the packages in the list

Now in v1.8.1 I get the following error:

TASK: [pkgs | Install additional packages] *********************************
fatal: [hal9000] => with_items expects a list or a set

FATAL: all hosts have already failed – aborting

Was this an intended change or is it a bug?

Best regards,
EP

we have a known issue with templating in lookup plugins (with_<lookup
plugin), for now try using explicit templating with_items:
"{{additional_packages|default()}}"