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,13 +47,16 @@ def create_ink(repo, repositories_base_dir, bin_dir, all_repos, quiet=False, pre
alias_name = repo.get("alias")
if alias_name:
alias_link_path = os.path.join(bin_dir, alias_name)
try:
if os.path.exists(alias_link_path) or os.path.islink(alias_link_path):
os.remove(alias_link_path)
os.symlink(link_path, alias_link_path)
if not quiet:
print(f"Alias '{alias_name}' has been set to point to {repo_identifier}.")
except Exception as e:
if not quiet:
print(f"Error creating alias '{alias_name}': {e}")
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)
try:
if os.path.exists(alias_link_path) or os.path.islink(alias_link_path):
os.remove(alias_link_path)
os.symlink(link_path, alias_link_path)
if not quiet:
print(f"Alias '{alias_name}' has been set to point to {repo_identifier}.")
except Exception as e:
if not quiet:
print(f"Error creating alias '{alias_name}': {e}")

View File

@@ -2,6 +2,7 @@ import os
import subprocess
import sys
import yaml
import tempfile
from pkgmgr.get_repo_identifier import get_repo_identifier
from pkgmgr.get_repo_dir import get_repo_dir
from pkgmgr.create_ink import create_ink
@@ -74,11 +75,34 @@ def install_repos(selected_repos, repositories_base_dir, bin_dir, all_repos, no_
if pip_packages:
cmd = "python3 -m pip install " + " ".join(pip_packages)
run_command(cmd, preview=preview)
# Install ansible collections if defined.
if "collections" in requirements:
print(f"Ansible collections found in {repo_identifier}, installing...")
cmd = "ansible-galaxy collection install -r requirements.yml"
run_command(cmd, cwd=repo_dir, preview=preview)
# 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:
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...")
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)
# Check if a requirements.txt file exists and install Python packages.
req_txt_file = os.path.join(repo_dir, "requirements.txt")