Ignored alias when equal to repo identifiert at link creation and optimized logic for ansible role and collection dependencies during install

This commit is contained in:
Kevin Veen-Birkenbach
2025-03-19 14:54:40 +01:00
parent 2c1bd9be0c
commit 85ff39c9ba
2 changed files with 42 additions and 15 deletions

View File

@@ -47,6 +47,9 @@ def create_ink(repo, repositories_base_dir, bin_dir, all_repos, quiet=False, pre
alias_name = repo.get("alias") alias_name = repo.get("alias")
if alias_name: if alias_name:
if alias_name == repo_identifier:
print(f"Skipped alias link creation. Alias '{alias_name}' and repository identifier '{repo_identifier}' are the same.")
else:
alias_link_path = os.path.join(bin_dir, alias_name) alias_link_path = os.path.join(bin_dir, alias_name)
try: try:
if os.path.exists(alias_link_path) or os.path.islink(alias_link_path): if os.path.exists(alias_link_path) or os.path.islink(alias_link_path):

View File

@@ -2,6 +2,7 @@ import os
import subprocess import subprocess
import sys import sys
import yaml import yaml
import tempfile
from pkgmgr.get_repo_identifier import get_repo_identifier from pkgmgr.get_repo_identifier import get_repo_identifier
from pkgmgr.get_repo_dir import get_repo_dir from pkgmgr.get_repo_dir import get_repo_dir
from pkgmgr.create_ink import create_ink from pkgmgr.create_ink import create_ink
@@ -74,10 +75,33 @@ def install_repos(selected_repos, repositories_base_dir, bin_dir, all_repos, no_
if pip_packages: if pip_packages:
cmd = "python3 -m pip install " + " ".join(pip_packages) cmd = "python3 -m pip install " + " ".join(pip_packages)
run_command(cmd, preview=preview) run_command(cmd, preview=preview)
# Install ansible collections if defined.
# Check if the requirements contain either 'collections' or 'roles'
if "collections" in requirements or "roles" in requirements:
print(f"Ansible dependencies found in {repo_identifier}, installing...")
# Build a new dictionary that only contains the Ansible dependencies
ansible_requirements = {}
if "collections" in requirements: if "collections" in requirements:
ansible_requirements["collections"] = requirements["collections"]
if "roles" in requirements:
ansible_requirements["roles"] = requirements["roles"]
# Write the ansible requirements to a temporary file.
with tempfile.NamedTemporaryFile(mode='w', suffix='.yml', delete=False) as tmp:
yaml.dump(ansible_requirements, tmp, default_flow_style=False)
tmp_filename = tmp.name
# Install Ansible collections if defined.
if "collections" in ansible_requirements:
print(f"Ansible collections found in {repo_identifier}, installing...") print(f"Ansible collections found in {repo_identifier}, installing...")
cmd = "ansible-galaxy collection install -r requirements.yml" cmd = f"ansible-galaxy collection install -r {tmp_filename}"
run_command(cmd, cwd=repo_dir, preview=preview)
# Install Ansible roles if defined.
if "roles" in ansible_requirements:
print(f"Ansible roles found in {repo_identifier}, installing...")
cmd = f"ansible-galaxy role install -r {tmp_filename}"
run_command(cmd, cwd=repo_dir, preview=preview) run_command(cmd, cwd=repo_dir, preview=preview)
# Check if a requirements.txt file exists and install Python packages. # Check if a requirements.txt file exists and install Python packages.