March 2019
Intermediate to advanced
412 pages
9h 49m
English
Task inclusions can be combined with loops as well. When adding a loop instance to a task inclusion (or a with_ loop if using a version of Ansible earlier than 2.5), the tasks inside the file will be executed with the item variable, which holds the place of the current loop's value. The entire include file will be executed repeatedly until the loop runs out of items. Let's update our example play to demonstrate this:
---- name: task inclusion hosts: localhost gather_facts: false tasks: - include: more-tasks.yaml loop: - one - two
We also need to update our more-tasks.yaml file to make use of the loop item:
--- - name: included task 1 debug: msg: "I am the first included task with {{ item }}" - name: included task ...Read now
Unlock full access