Functionality - For Loops (Legacy)
This type of loop repeats one or more operations for each item in a list.
Use for loops in a Playbook by defining a sequence in an action or step.
Read more about for loops on w3schools.
Steps & Actions
A sequence can be used to repeat both steps & actions.
It's also possible to have repeated actions inside repeated steps.
To support this functionality, the following sets of variables are used.
Step Sequence Variables
These can be used in all actions inside a repeated step.
Run a Step 3 Times
1 2 3 4 5 6 7 8 9
Action Sequence Variables
These can be used in a repeated action.
Run an Action 3 Times
1 2 3 4 5 6 7 8 9
This example uses a sequence to delete each Active Directory group in a list.
1. Create the Sequence
- An action is used to find empty groups whose names start with Test
- The output is saved as the
Find the Groups
1 2 3 4 5 6 7
2. Use the Sequence
groupsvariable is used as a sequence in the next action
This action requires the distinguishedName parameter
The parameter is supplied using the action item value Jinja2 syntax
Delete the Groups
1 2 3 4 5
Saving dynamic variables works differently when using sequenced actions.
An action that is not sequenced will run once & output a single piece of data.
Regardless of the type (list, dictionary, string, etc), there will only be one output.
The contents of a saved variable in this scenario will be the single output.
A sequenced action will, nearly always, run more than once.
Each time the action is run its output is added to a list.
The contents of a saved variable in this scenario will be a list of all the outputs.
This example runs the eval action with a sequence of numbers:
The eval expression uses the action item value Python syntax
The output from the action is saved as the
Sequenced Eval Action
1 2 3 4 5 6 7 8
Given the action was sequenced, the
results variable will contain:
1 2 3