'ansible roles split tasks/main.yml in multiple files
I want to split my tasks/main.yml into different files in my Ansible role. With defaults/ and vars/, Ansible supports the creation of a main directory instead of the main.yml, from which all *.yml files are included. Unfortunately, I can't find anything comparable for tasks. I don't want to enter every yml file in the main.yml again.
So I search for a way to "auto-include" all plays in the task-directory.
Does anyone has an idea or example?
Solution 1:[1]
You can use fileglob with include_tasks, like:
include_tasks: '{{item}}'
loop: "{{ lookup('fileglob' 'dir/*.yml' ) }}"
See also: https://github.com/ansible/ansible/issues/48866#issuecomment-440432119
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrew |
