Skip to content

Commit

Permalink
Make molecule reuse prerun from ansible-lint
Browse files Browse the repository at this point in the history
As ansible-lint is able to detect repository layout and run prepare
ansible from running it, we rely on its logic in order to assure
ansible is able to run properly.

This means that dependencies will be installed into .cache folder
and that the role import path will be updated to include it.
  • Loading branch information
ssbarnea committed Mar 19, 2021
1 parent bcb4cad commit 3fbc320
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ python:
- method: pip
path: .
extra_requirements:
- ansible-base
- docs
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 3 additions & 0 deletions src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 3fbc320

Please sign in to comment.