At my company, we currently use a patch file to get this result, and it’s been working great for over a year…so I figured it might be worth submitting a PR. However, I’m not sure how it would be received from a design perspective. Here’s the change:
We got tired of having dozens of main.yml files open in our editors (and buried as a single file inside of a directory), so we made a patch that allows the default loading mechanism of these files in roles:
tasks/main.yml
defaults/main.yml
handlers/main.yml
meta/main.yml
to also load these files:
tasks.yml
defaults.yml
handlers.yml
meta.yml
This makes it a lot easier to navigate and edit files in our ansible project. No more opening directories just to look at that one main.yml file inside. No more cycling through all the main.yml tabs in our editor to find the tasks file we were just working on.
Thanks, I had a feeling that was the case, which was why I didn’t go ahead and create the PR. I’m sure the reasoning is out there somewhere, but if you could link me to it, I’d appreciate it. I’m trying to understand why exactly it gets turned down, especially when it’s not breaking existing convention. This change makes things so much more readable…
This idea has been knocked down many times, for no good reason. I
have previously found, when searching on this topic, many occurrences
of the original author (DeHaan) in forums and issues basically just
saying "no" and the rationale was always "because I said so" or
"because I said so before." Any attempts to argue were met with "this
is a dead horse. Stop beating it." If you dig, you'll see the claim
that it's more "scalable" to use the full layout, but all the
counter-arguments -- that most/all roles only have single main.yml
files in these dirs, that it makes people confused by the layout, that
it makes editing more difficult, that it's superfluous structure in
the vast majority of cases -- were just met with a dictate. Ansible
can't be all things to all people, it was said. We follow
conventions. That ship has sailed.
Several of my colleagues have told me, when teaching them about
Ansible -- and I have thought myself -- how silly it is to have all
these directories with single files in them. Out of dozens of roles
so far, I have only had occasion a few times to populate these
directories with anything but single main.yml files. The
documentation is always encouraging users to factorize our plays into
roles, but well-factored roles will (almost by definition) be small
and use single main.yml files in defaults/, tasks/, meta/, etc, so I
find this contradictory.
My guess is that the core development team still holds this opinion --
for whatever reason -- and this change will never happen. If you
forked ansible with this patch (is it available btw?), I'd use your
fork I personally think it is the most inelegant aspect of
ansible, but opinions differ...
Scott, I completely agree with you, and you put it extremely well. I’m baffled at the stubbornness that seems to run counter to the project’s own design goals.
I don’t have a fork of ansible at this time, but I can share our patch with you now (this is based off of v2.2.1.0-1)…just copy the patch below to a local file and run patch -N <path_to_src>/ansible/lib/ansible/playbook/role/init.py patch_file.patch