File naming
This is the part of the naming convention that most developers
and operators need the least amount of help. This is almost natural
to them.
Therefore, we will just give some pointers. As all ansible code is broken into roles ansible galaxy dictates most of the files to be named main.yml in the directory structure it dictates. But we still have to add templates, files and maybe playbooks to get all the code functionality in there.
But there a a few files that escape the fixed structure, like "templates", "task_files" and "files".
Templates
As you already know, templates must have a fixed extension, so we won't bother you with that.
In a play, there can be a lot of templates used for the configuration of an application.
In the execution output of a play, you will not se the template beeing used, but you will
see the task name of the task applying the template. Keep those as close as possible to
eachother, when a play fails, you can identify the template that failed, from the task name
that failed. This can help to shorten a time consuming search.
Keep template names as close as you can to the file they create:
- httpd.conf.j2 - creates - httpd.conf
task_files
Many times, you must loop over a number of tasks in an single loop, the way for this is to include a tasks file, name this file to describe the loop this is included in.
Name the task that includes the file to that task at hand:
- name: Include loop_for_multi_tasks.yml
ansible.builtin.include_tasks:
file: loop_for_multi_tasks.yml
loop: "{{ some_var }}
This way, when thing fail, you know where to look.
Files
Most files thet will be copied are supplied to us developers and must not be changed.
That is the case for when they land on the system, not in how they reside in our code.
The most common thing with those files is, remembering where they came from, or who supplied
them. Sometimes it is best to have that name added to the filename in our repositories and
copy it to its original name on the system.
Best practice
Be sure the whole team is using the same naming schema, so there is never a doubt to a name of
any kind.