diff --git a/src/ansiblelint/cli.py b/src/ansiblelint/cli.py index c186fa851a..6e55512125 100644 --- a/src/ansiblelint/cli.py +++ b/src/ansiblelint/cli.py @@ -529,13 +529,16 @@ def get_config(arguments: list[str]) -> Namespace: f"'rich' or 'md' are supported with -f." ) + # save info about custom config file, as options.config_file may be modified by merge_config + has_custom_config = not options.config_file + file_config = load_config(options.config_file) config = merge_config(file_config, options) options.rulesdirs = get_rules_dirs(options.rulesdir, options.use_default_rules) - if options.project_dir == ".": + if has_custom_config and options.project_dir == ".": project_dir = guess_project_dir(options.config_file) options.project_dir = os.path.expanduser(normpath(project_dir)) diff --git a/src/ansiblelint/runner.py b/src/ansiblelint/runner.py index 681701647c..1b1a8e480b 100644 --- a/src/ansiblelint/runner.py +++ b/src/ansiblelint/runner.py @@ -124,7 +124,7 @@ def run(self) -> list[MatchError]: # noqa: C901 continue try: lintable.data - except RuntimeError as exc: + except (RuntimeError, FileNotFoundError) as exc: matches.append( MatchError( filename=lintable, diff --git a/src/ansiblelint/utils.py b/src/ansiblelint/utils.py index 5042749ebd..df5a09d6c2 100644 --- a/src/ansiblelint/utils.py +++ b/src/ansiblelint/utils.py @@ -859,6 +859,10 @@ def get_lintables( _logger.debug("Ignored %s due to: %s", path, exc) continue + if path.is_symlink() and not path.exists(): + _logger.warning("Ignored broken symlink %s -> %s", path, path.resolve()) + continue + lintables.append(Lintable(path)) # stage 2: guess roles from current lintables, as there is no unique