Externalize linting from molecule v3
See original GitHub issueProposal: lint-outsourcing
Author: Sorin Sbarnea <@ssbarnea> IRC: zbr
Date: 2019-09-15
- Status: Accepted after consultation on reddit.
- Proposal type: core design
- Estimated time to implement: 2 weeks
As would like to get some community feedback regarding a major change I would like to make for v3 version of Ansible Molecule. While doing other refactoring the need to rework linting become more pressing. The whole idea is to make molecule lint
easier to use and more flexible at the same time.
Another reason for this task is that linting should be performed at repository level and not at scenario level. One repository can have lots of roles and scenarios and linting at scenario level does not make much sense, creating a lot of duplicated configuration.
Molecule v3 :: Externalize linting
Linting is important but the reality is that each project may have different needs and preferences. Projects are likely to want to use more than linter, maybe to disable some checks.
We were close to completely removing linting support from molecule as it was adding a lot of complexity and coupling between different components. IRC channel has at least one question related to linting each week, the common ones where to configure it, how to disable it, why is running at the wrong step.
Having only one lint command which runs one configurable shell tasks is the way to go. This would allow users to use any linter they want, without having to modify molecule code to add support for a new linter.
We did our best to avoid execution failures when you start using v3 so this is what it will happen:
Migrating linter config from v2 to v3
If you removed or disabled linting in molecule.yml
, there is nothing for you to change.
An error would be raised if obsolete lint config items are found. In order to make it easier to migrate you can see this complex setup before and after migration.
# old v2 format:
lint:
name: yamllint
enabled: true
provisioner:
lint:
name: ansible-lint
options: ...
env: ...
verifier:
lint:
name: flake8
If you want to make molecule avoid any linting remove all linting related options from the config. If you still want to perform linting, look at example below:
# new v3 format, calling multiple linters:
lint: |
yamllint .
ansible-lint
flake8
Behaviour to implemented
- If no
lint
section exists assumes no linting - If old linting options are found, error will be displayed pointing to this ticket, which contain example on how to use new syntax
- Update documentation
- Update templates
Feedback needed
Please use up/down voting to show your support level or add comments if you have ideas about alternative approaches that should be considered.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:16 (16 by maintainers)
@ssbarnea, from your pad:
I’m -1 on this IIUC. Can multiple linters still be run? It’s unclear to me.
We should run all linters configured, not one. The behaviour should be the same as it is now but the configurations should be under a single place, not many. Users need multiple linters and expect to be able to do that.
To me, it feels like linting is not something that Molecule should be concerned with. The things I expect from Molecule to do well are:
The only exception to this rule would be creating a new role or collection. And this is where we can offer several “flavors” of initial setup. For example, we can create a
Makefile
in the root of the role/collection with some predefined targets such aslint
that would runansible-test sanity
oransible-list
or whatever,unit
for running unit tests usingansible-test units
,molecule
for running Molecule scenarios.This way, we can get rid of some cruft in the Molecule’s codebase while still guiding users to adequately tested roles and collections.