question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Externalize linting from molecule v3

See original GitHub issue

Proposal: 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:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
decentral1secommented, Nov 17, 2019

@ssbarnea, from your pad:

In the end we decided to have onlu one lint sequence which run one shell command.

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.

1reaction
tadeborocommented, Nov 16, 2019

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:

  1. Abstract away the nitty-gritty details about creating test containers or virtual machines.
  2. Run my playbooks against created hosts.
  3. Allow me to inspect instances while developing modules or roles.
  4. Clean after the test is done.

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 as lint that would run ansible-test sanity or ansible-list or whatever, unit for running unit tests using ansible-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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration — Molecule Documentation
Starting with v3, Molecule handles project linting by invoking and external lint commands as exemplified below. The decision to remove the complex linting...
Read more >
Proposal on Ansible Molecule v3 major linting change - Reddit
Molecule v3 :: Externalize linting. Linting is important but the reality is that each project may have different needs and preferences.
Read more >
Is there a way to run molecule tests with external dependencies?
1 Answer 1 · It is (out of blue, configured by other people). Use non-managed hosts in molecule. · We OK to run...
Read more >
Validate Ansible roles through molecule delegated driver
Molecule is a great tool for testing Ansible roles, it carries out a ... python 2.7; ansible 2.9.6; molecule 3.0.2; ansible-lint 4.2.0 ...
Read more >
Getting Started with Ansible Molecule - Victor's Blog
Quick guide to get you started with Ansible Molecule. ... Also edit molecule.yml so we are linting that external folder:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found