I am trying to understand how to configure Ansible linting as part of my testing phase but unfortunately all information and documentation out there about molecule seems to be outdated.
First, this is the molecule version I am running:
molecule --version molecule 6.0.2 using python 3.12
ansible:2.16.0
azure:23.5.0 from molecule_plugins
containers:23.5.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
default:6.0.2 from molecule
docker:23.5.0 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
ec2:23.5.0 from molecule_plugins
gce:23.5.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
podman:23.5.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0 vagrant:23.5.0 from molecule_plugins
And this is my molecule.yml
file.
---
dependency:
name: galaxy
options:
requirements-file: requirements.yml
platforms:
- name: molecule-debian
image: debian:12
driver:
options:
managed: False
login_cmd_template: "podman exec -ti {instance} bash"
ansible_connection_options:
ansible_connection: podman
provisioner:
name: ansible
lint:
name: ansible-lint
enabled: True
lint: ansible-lint
verifier:
name: ansible
When running molecule test
all steps are running as expected, however I don’t see any errors coming from the linter.
Also, it seems the molecule lint
command has been removed. There is a syntax
step in the default scenario, but I was unable to figure our how to use it. Again, docs are not helping.
What’s the proper way to manage the linting phase as part of the Ansible code testing with Molecule?
% molecule matrix test
INFO Test matrix
---
default:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- side_effect
- verify
- cleanup
- destroy
% molecule lint
Usage: molecule [OPTIONS] COMMAND [ARGS]...
Try 'molecule --help' for help.
Error: No such command 'lint'.
2
Answers
After further investigation, this is of course on purpose. New way is to run the linters separately.
https://github.com/ansible/molecule/discussions/3914
It seems that the version of Molecule you’re using doesn’t directly support the
molecule lint
command anymore. Instead, the linting can be configured within themolecule.yml
file under theprovisioner
section for theansible
driver. However, it looks like you’ve already enabled linting for Ansible:This should ideally trigger linting when Molecule runs the
create
,converge
, or any related playbook runs.Since the linting step isn’t flagging any issues, it might be worth ensuring that your Ansible Lint rules are correctly set up. Check if you have an
.ansible-lint
file or anansible-lint
section in youransible.cfg
file. These configurations might define the rules or checks that are applied during linting.Additionally, you could run the lint command directly using Ansible Lint:
This will manually invoke the Ansible Lint tool on your playbook or role and show any linting issues that it detects. Adjust the path according to where your Ansible content is located.
Lastly, for a detailed look at your Molecule configuration, ensure the specific Ansible lint rules are applied correctly. You might need to explore the output logs or adjust the verbosity of the Molecule test to see if it provides any additional information regarding the linting phase.