Chapter 6. Iterative Control Structures – Loops

You learned about conditional controls in the previous chapter. Our journey into Ansible's world of control structures continues with iterative controls. Often, we need to create a list of directories, install a bunch of packages, or define and walk over nested hashes or dictionaries. Traditional programming languages use the for or while loops for iteration. Ansible replaces them with the with statements.

In this chapter, we are going to learn about:

  • How to use iterative controls using the with statements
  • How to loop arrays to create multiple objects at once
  • How to define nested hashes and walk over them to create data-driven roles

The omnipotent with statement

Iterating plain lists, parsing dictionaries, ...

Get Ansible Playbook Essentials 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.