From the course: Ansible: From Basics to Guru by Pearson

Unlock this course with a free trial

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

Using loop to process a list of items

Using loop to process a list of items - Ansible Tutorial

From the course: Ansible: From Basics to Guru by Pearson

Using loop to process a list of items

In this video, we'll talk about loop. So let's try to understand what loop is doing. Loop is a keyword that allows you to iterate a simple list of items. Before Ansible 2.5, you would use with underscore instead, where the underscore is followed by some other items. So here you can see a very simple example where some services are started. And you know what? I'm just going to show you the code in this example. So let's call it loopdemo1.yml. And in there I am going to use name, demonstrate, loop, hosts, localhost, tasks. And what it all comes down to is name, show some looping. Oh, did you see, by the way, that I changed the indentation for name? My editor by default is using four spaces, so two additional spaces. That's not necessary and makes it harder to read, in fact, particularly if a task has a lot of arguments. I have a hard time making a difference between three spaces, four spaces and five spaces. Now it's only two, it's more readable. I'm going to use debug. And in debug…

Contents