From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Registering variables in loops

Registering variables in loops

From the course: Red Hat Certified Engineer (EX294) Cert Prep: 2 Using Ansible Playbooks

Start my 1-month free trial

Registering variables in loops

- [Instructor] I've included a script in this chapters exercise files named loop-register-vars.yml. This file registers the output of a loop to a variable. Let's take a look at it. Change to this chapters directory and the exercise files and then load the file in the vim. Having vim loop-register-vars.yml and hit enter. Expand folds if necessary by pressing the Z uppercase R Keys. We can see a task named output loop to registered var. I also have two shell module lines. The first one echos the item variable and the second one is commented out and uses CAT to view the item variable. We'll use this line in the moment. Then we loop two items in a list and at the end of that task, we register the variable named echo. In the next task, we manage commands and loops that return a non-zero value. We do this by using the WIN clause to check if the returning code value in the item variable is non-zero. Then we…

Contents