From the course: Ansible Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Using loops

Using loops

- [Instructor] One of the many reasons that people love Ansible is its ability to automate the repetition that we must often perform in IT. Maybe we need to ensure that the permissions are changed on many different files. Or perhaps we need to create hundreds of new users accounts. Loops are the magic behind much of this repetition. In fact, loops were great with conditionals for performing acts until a certain value is reached. In Ansible, we have simple loops and complex loops. More complex loops can be used to do things like iterate over nested lists, or retry a task until a condition is met. So let's go to our command line here on the control node, and let's examine the first loop example that I have for us. So we're just going to cat loop1.yml and that's .yml, there we go. And we can see we're just running a playbook against our web servers. And notice I have a variables section and that variable section defines a…

Contents