Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'molecule init' doesn't comply with documented 'molecule lint' configuration #3481

Closed
Fixmetal opened this issue Mar 30, 2022 · 0 comments · Fixed by #3503, #3680 or #3750
Closed

'molecule init' doesn't comply with documented 'molecule lint' configuration #3481

Fixmetal opened this issue Mar 30, 2022 · 0 comments · Fixed by #3503, #3680 or #3750
Labels

Comments

@Fixmetal
Copy link

Fixmetal commented Mar 30, 2022

Issue Type

  • Bug report

Molecule and Ansible details

$ ansible --version
ansible [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/enomis/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/enomis/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.3 (main, Mar 18 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)]
  jinja version = 3.0.1
  libyaml = True

$ molecule --version
molecule 3.6.1 using python 3.10 
    ansible:2.12.2
    delegated:3.6.1 from molecule
    podman:1.1.0 from molecule_podman requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0

Molecule installation method:

  • pip

Ansible installation method:

  • pip

Detail any linters or test runners used:

  • yamllint
  • ansible-lint
  • flake8
$ ansible-lint --version
ansible-lint 6.0.1 using ansible 2.12.2
$ flake8 --version
4.0.1 (mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes: 2.4.0) CPython 3.10.3 on Linux
$ yamllint --version
yamllint 1.26.3

Desired Behavior

When creating a new role I would expect molecule to create a consistent skeleton for itself that complies with FQCN at the very least. This is because, as stated by doc:

Molecule supports only the latest two major versions of Ansible (N/N-1), meaning that if the latest version is 2.9.x, we will also test our code with 2.8.x.

So as of today, I'm expecting it to support these (if I'm mistaken here I'd suggest a more clear specification in the doc):

  • ansible-core 2.12
  • ansible-core 2.11
  • ansible 5.5
  • ansible 5.4

After applying as suggested about linting by the https://github.com/ansible-community/molecule/blob/v3.6.1/docs/configuration.rst#lint and populating proper info to meta/main.yml linter shouldn't complain at all, like:

$ cat molecule/default/molecule.yml 
---
dependency:
  name: galaxy
driver:
  name: delegated
platforms:
  - name: instance
provisioner:
  name: ansible
verifier:
  name: ansible
lint: |
  set -e
  yamllint .
  ansible-lint
  flake8

$ molecule lint
INFO     default scenario test matrix: dependency, lint
INFO     Performing prerun...
INFO     Set ANSIBLE_LIBRARY=/home/enomis/.cache/ansible-compat/7778e3/modules:/home/enomis/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/enomis/.cache/ansible-compat/7778e3/collections:/home/enomis/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/enomis/.cache/ansible-compat/7778e3/roles:/home/enomis/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Using /home/enomis/.ansible/roles/acme.test symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > lint
WARNING  Loading custom .yamllint config file, this extends our internal yamllint config.
$ echo $?
0
$

Actual Behaviour

molecule lint also checks molecule directory, generating these errors:

  • FQCNs not used in Molecule skeleton
  • Handler not used in default destroy.yml file
$ molecule --debug lint
DEBUG    Validating schema /tmp/test/molecule/default/molecule.yml.
INFO     default scenario test matrix: dependency, lint
INFO     Performing prerun...
INFO     Set ANSIBLE_LIBRARY=/home/enomis/.cache/ansible-compat/9f86d0/modules:/home/enomis/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/enomis/.cache/ansible-compat/9f86d0/collections:/home/enomis/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/enomis/.cache/ansible-compat/9f86d0/roles:/tmp/test:.
INFO     Using /tmp/test/acme.test symlink to current repository in order to enable Ansible to find the role using its expected full name.
INFO     Running default > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > lint
WARNING  Loading custom .yamllint config file, this extends our internal yamllint config.
WARNING  Listing 8 violation(s) that are fatal
fqcn-builtins: Use FQCN for builtin actions.
molecule/default/converge.yml:5 Task/Handler: Include acme.test

fqcn-builtins: Use FQCN for builtin actions.
molecule/default/create.yml:13 Task/Handler: Populate instance config dict

fqcn-builtins: Use FQCN for builtin actions.
molecule/default/create.yml:24 Task/Handler: Convert instance config dict to a list

fqcn-builtins: Use FQCN for builtin actions.
molecule/default/create.yml:28 Task/Handler: Dump instance config

fqcn-builtins: Use FQCN for builtin actions.
molecule/default/destroy.yml:12 Task/Handler: Populate instance config

fqcn-builtins: Use FQCN for builtin actions.
molecule/default/destroy.yml:16 Task/Handler: Dump instance config

no-handler: Tasks that run when changed should likely be handlers.
molecule/default/destroy.yml:16 Task/Handler: Dump instance config

fqcn-builtins: Use FQCN for builtin actions.
molecule/default/verify.yml:8 Task/Handler: Example assertion

You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list:  # or 'skip_list' to silence them completely
  - fqcn-builtins  # Use FQCN for builtin actions.
  - no-handler  # Tasks that run when changed should likely be handlers.

Finished with 8 failure(s), 0 warning(s) on 19 files.
WARNING  Retrying execution failure 2 of: s e t   - e 
 y a m l l i n t   . 
 a n s i b l e - l i n t 
 f l a k e 8 

CRITICAL Lint failed with error code 2
$ echo $?
1
$

Steps to reproduce:

molecule init role acme.test
cd acme.test
cat<<EOF>>molecule/default/molecule.yml 
lint: |
  set -e
  yamllint .
  ansible-lint
  flake8
EOF
<EDIT meta/main.yml w/Author, Description, Platforms>
molecule lint
@Fixmetal Fixmetal added the bug label Mar 30, 2022
ziegenberg added a commit to ziegenberg/molecule that referenced this issue Apr 11, 2022
Fixes: ansible#3481

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
ssbarnea pushed a commit that referenced this issue Apr 12, 2022
Fixes: #3481

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
muellerbe added a commit to muellerbe/molecule that referenced this issue Oct 12, 2022
davedittrich pushed a commit to davedittrich/molecule that referenced this issue Oct 24, 2022
muellerbe pushed a commit to muellerbe/molecule that referenced this issue Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant