ansible Ansible: Looping with_items - predefined list


You can also loop over a variable list.

From vars:

  - hotdog
  - ice cream
  - chips

and then the loop:

- name: create directories for storing my snacks
  file: path=/etc/snacks/{{ item }} state=directory
  with_items: '{{ favorite_snacks }}'

If you are using Ansible 2.0+ you must use quotes around the call to the variable.