diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5e026e524d..bded278be0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,15 +50,16 @@ repos: entry: mypy src/ pass_filenames: false additional_dependencies: + - ansible-lint>=5.0.5a0 - packaging - enrich>=1.2.5 - subprocess-tee>=0.2.0 - repo: https://github.com/pre-commit/mirrors-pylint - rev: v2.6.0 + rev: v2.7.2 hooks: - id: pylint additional_dependencies: - - ansible-base + - ansible-lint>=5.0.5a0 - enrich>=1.2.5 - subprocess-tee>=0.2.0 - testinfra diff --git a/.readthedocs.yml b/.readthedocs.yml index 62b6635ea1..804662309f 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -12,4 +12,5 @@ python: - method: pip path: . extra_requirements: + - ansible-base - docs diff --git a/mypy.ini b/mypy.ini index 3f2d25be96..cca70f73fb 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,6 +7,9 @@ warn_redundant_casts = True no_implicit_optional = True # 3rd party ignores, to remove once they add hints +[mypy-ansiblelint.*] +ignore_missing_imports = True + [mypy-cerberus.*] ignore_missing_imports = True diff --git a/setup.cfg b/setup.cfg index a039797e49..a3148dc30e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,6 +66,7 @@ setup_requires = # These are required in actual runtime: install_requires = + ansible-lint >= 5.0.5a0 # only for the prerun functionality cerberus >= 1.3.1 click >= 7.0, < 8.0 # https://github.com/click-contrib/click-help-colors/issues/12 click-completion >= 0.5.1 @@ -120,9 +121,10 @@ test = pytest-xdist >= 2.1.0 pytest >= 6.1.2 lint = - ansible-lint[core,yamllint] >= 5.0.2, < 6 + # ansible-lint is not a core dependency, duplicating it here would confuse pip flake8 >= 3.8.4 pre-commit >= 2.10.1 + yamllint [options.entry_points] console_scripts = diff --git a/src/molecule/command/base.py b/src/molecule/command/base.py index 02ea3885d1..cf3664e5cc 100644 --- a/src/molecule/command/base.py +++ b/src/molecule/command/base.py @@ -28,6 +28,7 @@ from typing import Any, Callable import click +from ansiblelint.prerun import prepare_environment from click_help_colors import HelpColorsCommand, HelpColorsGroup import molecule.scenarios @@ -90,6 +91,8 @@ def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=() :returns: None """ + prepare_environment() + glob_str = MOLECULE_GLOB if scenario_name: glob_str = glob_str.replace("*", scenario_name) diff --git a/src/molecule/provisioner/ansible.py b/src/molecule/provisioner/ansible.py index e3ffb5cd0b..99c859ee1c 100644 --- a/src/molecule/provisioner/ansible.py +++ b/src/molecule/provisioner/ansible.py @@ -453,6 +453,7 @@ def default_env(self): ), "/usr/share/ansible/roles", "/etc/ansible/roles", + *os.environ.get("ANSIBLE_ROLES_PATH", "").split(":"), ] ), self._config.ansible_collections_path: ":".join(collections_path_list), diff --git a/tox.ini b/tox.ini index 1be3b5b895..913a472628 100644 --- a/tox.ini +++ b/tox.ini @@ -47,6 +47,7 @@ deps = dockerfile: ansible>=2.9.12 selinux py{36,37}: importlib-metadata<2,>=0.12 + py: ansible-base extras = docker lint @@ -61,7 +62,7 @@ commands = # failsafe as pip may install incompatible dependencies pip check # failsafe for preventing changes that may break pytest collection - sh -c "PYTEST_ADDOPTS= python -m pytest -p no:cov --collect-only 2>&1 >{envlogdir}/collect.log" + sh -c "PYTEST_ADDOPTS= python -m pytest -p no:cov --collect-only" # -n auto used only on unit as is not supported by functional yet # html report is used by Zuul CI to display reports python -m pytest src/molecule/test/unit/ {env:_EXTRAS} {env:PYTEST_ADDOPTS:} {posargs} @@ -102,6 +103,7 @@ commands = 'import pathlib; '\ 'docs_dir = pathlib.Path(r"{toxinidir}") / "docs/docstree/html"; index_file = docs_dir / "index.html"; print(f"\nDocumentation available under `file://\{index_file\}`\n\nTo serve docs, use `python3 -m http.server --directory \{docs_dir\} 0`\n")' extras = + ansible-base docs [testenv:docs-livereload]