From 5f52c57973f1e814574d59438166fb13950f334f Mon Sep 17 00:00:00 2001 From: Xabier Napal Date: Sat, 10 Jul 2021 16:17:46 +0200 Subject: [PATCH] fix(prerun): detect collection and role from project dir (#1654) --- src/ansiblelint/prerun.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/ansiblelint/prerun.py b/src/ansiblelint/prerun.py index e20755d9d32..0b3de325510 100644 --- a/src/ansiblelint/prerun.py +++ b/src/ansiblelint/prerun.py @@ -258,9 +258,10 @@ def _symlink_galaxy_install(link_path) -> None: def _install_galaxy_role() -> None: """Detect standalone galaxy role and installs it.""" - if not os.path.exists("meta/main.yml"): + galaxy_path = "%s/meta/main.yml" % options.project_dir + if not os.path.exists(galaxy_path): return - yaml = yaml_from_file("meta/main.yml") + yaml = yaml_from_file(galaxy_path) if 'galaxy_info' not in yaml: return @@ -309,21 +310,17 @@ def _install_galaxy_role() -> None: def _install_galaxy_collection() -> None: """Detect standalone galaxy collection and installs it.""" - if not os.path.exists("galaxy.yml"): + galaxy_path = "%s/galaxy.yml" % options.project_dir + if not os.path.exists(galaxy_path): return - yaml = yaml_from_file("galaxy.yml") - if not yaml: - # ignore empty galaxy.yml file - return - namespace = yaml.get('namespace', None) - collection = yaml.get('name', None) - if not namespace or not collection: + yaml = yaml_from_file(galaxy_path) + if 'namespace' not in yaml or 'name' not in yaml: return p = pathlib.Path( - f"{options.cache_dir}/collections/ansible_collections/{ namespace }" + f"{options.cache_dir}/collections/ansible_collections/{yaml['namespace']}" ) p.mkdir(parents=True, exist_ok=True) - link_path = p / collection + link_path = p / yaml['name'] _symlink_galaxy_install(link_path) _logger.info( "Using %s symlink to current repository in order to enable Ansible to find the collection using its expected full name.",