ansible-lint
is an amazing tool! Following its recommendations has helped our large and growing configuration-as-code base age like wine rather than like milk.
And it’s necessarily opinionated, more so than any humans I know. It has to be, though, in order to nip sloppy practices in the bud before they flower and fruit into a harvest of technical debt. You can reclassify individual errors as warnings or even ignore them altogether in cases you decide either aren’t important to you or that you have not yet fixed across your projects. Ultimately you retain responsibility for the quality of your code base.
With ansible-lint
having such strong opinions, the onus is on the gate-keepers of its rules for getting it right.
For example, when ansible-lint
complained that our task names “should start with an uppercase letter” we groaned quite a bit as this violated our internal style guide at the time wherein any strings that were “ours” — such as variable, group, and task names — started with lower-case letters. We reclassified it as a warning and, over time, changed all our task names accordingly.
Some tasks are handlers. We were already unhappy notifying handlers by their task names, as those names were too free-form for our liking anyway. Now we needed to change them all to meet the name[casing]
rule. Fortunately, handlers support listen:
so a handler could go from this:
- name: apply pending changes
to a much more disciplined set of constructed notify strings, like this:
- name: Apply pending changes
listen:
- mw_tablinx_install_pending_changes
- mw_kronos_bounce_config_tier
These more disciplined notify strings embody an indication of their containing roles and their relationships to notifying tasks, while the for-human-consumption task names satisfy ansible-lint
’s name[casing]
requirements. It’s a win-win all around.
Except that, after a recent upgrade, ansible-lint
is now applying the same name[casing]
rule to notify strings as it applies to task names. This is a case where, in my opinion, ansible-lint
goes beyond opinionated; it’s just flat out wrong. These strings are not English (or pick your language) phrases. They are functional character strings. Yet because ansible-lint
is treating them with the same rule it uses for task names, we can’t ignore the name[casing]
rule for notify strings without also ignoring it for task names. Notify strings are much closer to variable and role/collection names than they are to task names. This feels like an opinionated tool expressing an opinion simply because it can rather than either to accomplish a positive goal or to avoid identifiable issues.
The easy fix would be to create a different rule for notify strings separate from those for task names. Then we could ignore it and move on. I do have to wonder, though, exactly what problem such a rule for notify strings is hoping to avoid, and whether such problems match those created by the same apparently aesthetics-based opinions-as-code embodied in ansible-lint
.