diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 6df19d2dad..019838f1cd 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -53,7 +53,7 @@ log_entries, options, ) -from ansiblelint.constants import RC +from ansiblelint.constants import RC, SKIP_SCHEMA_UPDATE from ansiblelint.loaders import load_ignore_txt from ansiblelint.runner import get_matches from ansiblelint.skip_utils import normalize_tag @@ -305,7 +305,22 @@ def main(argv: list[str] | None = None) -> int: _logger.debug("Options: %s", options) _logger.debug("CWD: %s", Path.cwd()) - if not options.offline: + # checks if we have `ANSIBLE_LINT_SKIP_SCHEMA_UPDATE` set to bypass schema + # update. Also skip if in offline mode. + # env var set to skip schema refresh + skip_schema_update = ( + bool( + int( + os.environ.get( + SKIP_SCHEMA_UPDATE, + "0", + ), + ), + ) + or options.offline + ) + + if not skip_schema_update: # pylint: disable=import-outside-toplevel from ansiblelint.schemas.__main__ import refresh_schemas diff --git a/src/ansiblelint/constants.py b/src/ansiblelint/constants.py index 4b146476a9..ad051ba47f 100644 --- a/src/ansiblelint/constants.py +++ b/src/ansiblelint/constants.py @@ -6,11 +6,13 @@ DEFAULT_RULESDIR = Path(__file__).parent / "rules" CUSTOM_RULESDIR_ENVVAR = "ANSIBLE_LINT_CUSTOM_RULESDIR" RULE_DOC_URL = "https://ansible-lint.readthedocs.io/rules/" +SKIP_SCHEMA_UPDATE = "ANSIBLE_LINT_SKIP_SCHEMA_UPDATE" ENV_VARS_HELP = { CUSTOM_RULESDIR_ENVVAR: "Used for adding another folder into the lookup path for new rules.", "ANSIBLE_LINT_IGNORE_FILE": "Define it to override the name of the default ignore file `.ansible-lint-ignore`", "ANSIBLE_LINT_WRITE_TMP": "Tells linter to dump fixes into different temp files instead of overriding original. Used internally for testing.", + SKIP_SCHEMA_UPDATE: "Tells ansible-lint to skip schema refresh.", } EPILOG = (