From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Nesting loops - Ansible Tutorial
From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Nesting loops
- [Instructor] I have a computer science background with a good bit of programming experience, but don't get it wrong, I am no programmer, but I can play one on TV on occasion. With this in mind, I'll join the fray and say that Ansible is not a programming language. And if you insist that it is, I would say it's not a great one. What I mean is that sometimes, complex processing tasks can be a little hairy. Case in point, how does an admin perform nested loops? This is a concept that I semi-regularly employ where I'm looping through a list of data and I need to perform an additional loop over that data. In a programming language, it is a simple matter, but in Ansible it requires a little extra work. The best way to accomplish a nested loop is via a task file. It's often easier to show rather than to tell. Have a look at my playbook I've named nested-loop.yml. I'll start with the first task, which uses the shell module to grab a list of all the users on the system and saves that list to…
Contents
-
-
-
(Locked)
Installing collections2m 20s
-
Construct a simple playbook4m 19s
-
(Locked)
Using variables5m 7s
-
(Locked)
Using loops2m 45s
-
(Locked)
Adding conditionals4m 57s
-
(Locked)
Utilizing blocks3m 49s
-
(Locked)
Exploring templates4m 29s
-
(Locked)
Discovering handlers2m 23s
-
(Locked)
Using tags2m 53s
-
(Locked)
Testing plays with check mode2m 15s
-
(Locked)
Conditional failure with assert2m 20s
-
(Locked)
Failure and change control2m 32s
-
(Locked)
Nesting loops3m 29s
-
(Locked)
Creating dynamic inventory files3m 7s
-
(Locked)
Challenge: Create a complex playbook1m 17s
-
Solution: Verify the complex playbook2m 52s
-
(Locked)
-
-
-
-