0

I am new to using molecule and want to enable molecule for my ansible content. This content is a folder containing three playbooks and a folder roles with 8 roles which are used in the playbooks. The playbooks run without problems.

Now I wanted to use molecule with them and my fist step was trying to add linting.

I tested linting with running the command

ansible-lint * --nocolor &>ansible-lint.out

I also created a molecule scenario and added in the file molecule/default/molecule.yml the configuration for lint

---
dependency:
  name: galaxy
driver:
  name: podman
platforms:
  - name: instance
    image: quay.io/centos/centos:stream8
    pre_build_image: true
provisioner:
  name: ansible
verifier:
  name: ansible
lint: |
  set -e
  yamllint .
  ansible-lint .

Wen I run molecule lint the same file will be analysed as when I run ansible-lint *. However it seems that different rules are used. With ansible-lint the maximum allowed line length is 160 while with molecule lint it is 80. Further on with ansible-lint I see violations which are not reported bye molecule lint. I have not configured the rules to use and are use the standard configuration. In both situation ansible-lint --version reports.

$ ansible-lint --version
ansible-lint 6.5.0 using ansible 2.13.3

Can someone explain to me why molecule lint is not using the same standard configuration as ansible-lint. Is there some documentation which explains this.

And how can I configure molecule to use the default rules from ansible-lint.

And is molecule lint executed inside the container or outside? I would assume outside.

Frank

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
grafra
  • 411
  • 6
  • 16
  • Create a `.yamllint` file where you change the default line lenght to align it to the default in ansible-lint. https://yamllint.readthedocs.io/en/stable/configuration.html – Zeitounator Aug 29 '22 at 14:18
  • Ansible-lint can be configured through `.ansible-lint` or `.config/ansible-lint.yml`, see [Ansible Lint Docs](https://ansible-lint.readthedocs.io/en/latest/configuring/#configuration-file). – phanaz Aug 30 '22 at 08:21
  • Thanks for the hint. I think my problem came from the fact that yamllint in its standard configuration use a different maximal file length of 80 chars. Since I had longer lines the yamllint command exited with an error code and thus I never saw the output of the ansible-lint. I will check whether I can configure the max line length. But I see the problem that each error in yaml lint will prevent the ansible-lint from running. – grafra Aug 30 '22 at 13:33

2 Answers2

0

Yes the my problem was, that I was not aware that the first problem reported by yamllint will raise an exit code different of 0 and thus prevent the ansible-lint from running. Thus I did never see the output from ansible-lint.

A second problem is that ansible-lint seem to invoke yamllint but with different default rules.

grafra
  • 411
  • 6
  • 16
0

The linting command inside molecule is deprecated and was already removed from main branch.

Just run ansible-lint standalone and you will not have such problems.

sorin
  • 161,544
  • 178
  • 535
  • 806