By default, Ansible looks for the tasks for a role in a main.yml. I have too many main.yml files and I'd like to rename this to rolename.yml or something that is more unique. How can I change Ansible's default behavior to use rolename.yml instead of tasks/main.yml?
As Bruce already pointed out this is hardcoded. But I have an issue with this behavior as well, as my IDE displays the filename in the tab and I used to have a bazillion tabs named "main.yml".
My standard setup is to have two files:
In the main.yml then simply is an include
task to the role-name.yml. Along with this include I handle tags, because I want all my roles to be tagged with their name.
---
- include: role-name.yml
tags: role-name
...
Unfortunately there's no way to do this. The name main.yml
is hardcoded into the ansible source code. (If you really care, look for the function _resolve_main
in this file.)
Role tasks will always be in the file roles/<rolename>/tasks/main.yml
, variables in roles/<rolename>/vars/main.yml
, etc. Because the path that each file lives in provides the full detail of the name of the role & purpose of the file, there's really no need to change the name from main.yml. You would just end up with something like roles/<rolename>/tasks/<rolename>.yml
which is redundant.
This is all documented in Ansible's Best Practices document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With