Molecule: yamllint is not found when running 'lint' target as of Molecule 3.0.7

Created on 17 Aug 2020  路  16Comments  路  Source: ansible-community/molecule

Issue Type

  • Bug report

Molecule and Ansible details

Ansible 2.9.12
Molecule 3.0.7

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Detail any linters or test runners used:

yamllint and ansible-lint, test is run in Travis CI environment

Desired Behavior

Linters should run without issue.

Actual Behaviour

--> Scenario: 'default'
--> Action: 'lint'
--> Executing: set -e
yamllint .
ansible-lint
/bin/sh: 2: yamllint: not found
ERROR: Lint failed: Command 'set -e
yamllint .
ansible-lint
' returned non-zero exit status 127.: Command 'set -e
yamllint .
ansible-lint
' returned non-zero exit status 127.

See failed build: https://travis-ci.org/github/geerlingguy/ansible-role-clamav/jobs/718754330#L470

It looks like this bug was introduced in the 3.0.7 release. If I pip install molecule===3.0.6 the problem goes away.

bug

Most helpful comment

OK, here's what's going on:

I have yamllint installed through Fedora package manager. So without passing the PATH value through to the environment my system is picking up /usr/bin/yamllint. When I send through the PATH value, I get the yamllint that's installed in my virtualenv.

Since the previous behavior of molecule was to run with the entire invoking environment, I'm going to submit a patch that passes the entirety of os.environ through along with the MOLECULE_ values unless someone objects to that.

All 16 comments

Same issue with Molecule 3.0.7. Works fine with any 3.0.x version prior to 3.0.7.

Thanks for raising up the issue @geerlingguy.

I don't see anything else in the diff that is the likely cause, but I'm not sure how it would have that effect. Is it also stripping out the PATH variable, maybe? Seems like something we should wrap a test case around.

If I run env within the lint block, I see only the following variables:

MOLECULE_DRIVER_NAME=docker
MOLECULE_STATE_FILE=/home/xxx/.cache/molecule/ansible-role-consul-service/default/state.yml
MOLECULE_DEPENDENCY_NAME=galaxy
MOLECULE_ENV_FILE=<current directory>/.env.yml
MOLECULE_PROJECT_DIRECTORY=<current directory>
MOLECULE_INSTANCE_CONFIG=/home/xxx/.cache/molecule/ansible-role-consul-service/default/instance_config.yml
MOLECULE_PROVISIONER_NAME=ansible
MOLECULE_EPHEMERAL_DIRECTORY=/home/xxx/.cache/molecule/ansible-role-consul-service/default
MOLECULE_SCENARIO_NAME=default
MOLECULE_DEBUG=False
MOLECULE_INVENTORY_FILE=/home/xxx/.cache/molecule/ansible-role-consul-service/default/inventory/ansible_inventory.yml
MOLECULE_VERIFIER_NAME=xxx
MOLECULE_VERIFIER_TEST_DIRECTORY=<current directory>/molecule/default/tests
MOLECULE_FILE=/home/xxx/.cache/molecule/ansible-role-consul-service/default/molecule.yml
MOLECULE_SCENARIO_DIRECTORY=<current directory>/molecule/default
PWD=<current directory>

No PATH variable here, so it seems to be stripped out.

@sduthil I've been trying to replicate this error in the test environment, but I'm not getting the errors y'all are seeing. I'm also seeing no value of PATH in a call to "env", but "yamllint" is executing just fine.

    --> Executing: set -e
    env
    yamllint .
    MOLECULE_FILE=/home/ghelling/.cache/molecule/docker/default/molecule.yml
    MOLECULE_VERIFIER_NAME=ansible
    MOLECULE_DEPENDENCY_NAME=galaxy
    MOLECULE_SCENARIO_DIRECTORY=/home/ghelling/src/molecule/molecule/test/scenarios/driver/docker/molecule/default
    MOLECULE_INVENTORY_FILE=/home/ghelling/.cache/molecule/docker/default/inventory/ansible_inventory.yml
    PWD=/home/ghelling/src/molecule/molecule/test/scenarios/driver/docker
    MOLECULE_PROVISIONER_NAME=ansible
    MOLECULE_INSTANCE_CONFIG=/home/ghelling/.cache/molecule/docker/default/instance_config.yml
    MOLECULE_DEBUG=False
    MOLECULE_DRIVER_NAME=docker
    SHLVL=1
    MOLECULE_VERIFIER_TEST_DIRECTORY=/home/ghelling/src/molecule/molecule/test/scenarios/driver/docker/molecule/default/tests
    MOLECULE_STATE_FILE=/home/ghelling/.cache/molecule/docker/default/state.yml
    MOLECULE_SCENARIO_NAME=default
    MOLECULE_ENV_FILE=/home/ghelling/src/molecule/molecule/test/scenarios/driver/docker/.env.yml
    MOLECULE_PROJECT_DIRECTORY=/home/ghelling/src/molecule/molecule/test/scenarios/driver/docker
    MOLECULE_EPHEMERAL_DIRECTORY=/home/ghelling/.cache/molecule/docker/default
    _=/usr/bin/env

I'm not sure that the missing PATH value is the actual culprit. This is working fine on my local machine with the released molecule==3.0.7. There's something fundamentally different going on, now.

OK, here's what's going on:

I have yamllint installed through Fedora package manager. So without passing the PATH value through to the environment my system is picking up /usr/bin/yamllint. When I send through the PATH value, I get the yamllint that's installed in my virtualenv.

Since the previous behavior of molecule was to run with the entire invoking environment, I'm going to submit a patch that passes the entirety of os.environ through along with the MOLECULE_ values unless someone objects to that.

@greg-hellings - Yeah, I'm installing yamllint through pip, so it ends up in /usr/local/bin/yamllint, which is not in the default system PATH (which doesn't include /usr/local/bin).

Exactly, the problem is when you install the yamlint (or any other from the "linter" configuration) from pip or/and in a virtualenv (I have the same error since yesterday, and after fight with my environment for hours, I found this post xDDDD)

I'm having this same issue with yamllint and ansible-lint installed via pip using pyenv. I have ~/.pyenv/shims in my PATH and the linting tools are not found by molecule.

For a quick-and-dirty workaround while waiting for the next release, add the following PATH= line in the lint block, before running the linters:

lint: |
  set -e
  PATH=${PATH}
  yamllint .
  ...

The PATH variable will be expanded by molecule BEFORE running the shell script, instead of being expanded by the shell of the lint block.

2783 should address this. Please give it a gander to see

Which version of the release has this been fixed?

You must install yamllint yourself because it is a soft-dependency, not a hard one. Not sure how you install molecule but if you have troubles you may want to use the https://github.com/ansible-community/toolset prebuild container that combines all the tooling.

The passing down of the PATH environment variables was fixed in molecule 3.0.8 (see the Milestone section of the closing PR).

We are using molecule thru tox.ini and not through docker containers. So just adding a yamllint to tox.ini as a soft dependency should resolve the issue?

https://github.com/lfit/ansible-roles-lf-recommended-tools/blob/master/tox.ini#L14

Was this page helpful?
0 / 5 - 0 ratings