0

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?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
FDo
  • 17
  • 3
  • 2
    There is no auto-include in tasks. Only explicit *inlcude_tasks* and *import_tasks*. Btw. in what order should the tasks be executed if there were any auto-include? – Vladimir Botka Jan 31 '22 at 15:46

1 Answers1

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

Andrew
  • 3,912
  • 17
  • 28
  • Thank you, that was the way , i was searching for. At this [link](https://github.com/ansible/ansible/issues/32792) i found a nice implementation. – FDo Jan 31 '22 at 21:34