ansible Ansible: Looping with_items - predefined list

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

You can also loop over a variable list.

From vars:

favorite_snacks:
  - 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.



Got any ansible Question?