Standard loops

Standard loops in playbooks are often used to easily perform similar tasks multiple times. The syntax for standard loops is very easy: the {{ item }} variable is the placeholder looping over the with_items list. For example, take a look at the following section in the chapter5_4.yml playbook:

      tasks:        - name: echo loop items          command: echo {{ item }}          with_items: ['r1', 'r2', 'r3', 'r4', 'r5']   

It will loop over the five list items with the same echo command:

TASK [echo loop items] *********************************************************changed: [192.168.199.185] => (item=r1)changed: [192.168.199.185] => (item=r2)changed: [192.168.199.185] => (item=r3)changed: [192.168.199.185] => (item=r4)changed: [192.168.199.185] => (item=r5) ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.