1

I have had tasks work for each of these 'with_items' scenarios at one point or another:

 with_items: ec2.instances

or

  with_items: '{{ ec2.instances }}'

or

 with_items: "{{ ec2.instances }}"

How do I know when to use the correct one. If I knew, then I wouldn't be running into a trial-and-error situation as much of the time.

Thanks for the help!

Cloudish123
  • 847
  • 1
  • 9
  • 14

1 Answers1

3

Ansible < 2.2 (deprecated since 2.1) – bare variables:

with_items: ec2.instances

Ansible >= 2.2 – templated:

with_items: '{{ ec2.instances }}'

From release notes:

Removed Deprecated:

  • with_ 'bare variable' handling, now loop items must always be templated {{ }} or they will be considered as plain strings.

Single or double quotes doesn't matter in this case.
You can read about differences in quotes from other SO questions.

Community
  • 1
  • 1
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193