A with_items loop in ansible can be used to easily loop over values.
- name: Add lines to this file
lineinfile: dest=/etc/file line={{ item }} state=present
with_items:
- Line 1
- Line 2
- Line 3
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 ...
It is possible to create more complex loops with dictionaries.
From vars:
packages:
- present: tree
- present: nmap
- absent: apache2
then the loop:
- name: manage packages
package: name={{ item.value }} state={{ item.key }}
with_items: '{{ packages }}'
Or, if you don't like ...