Retry Ansible Galaxy calls

Change-Id: Ic0e33c4f2939c36ed80caa3ec1015cf53a4d93e2
This commit is contained in:
Michal Nasiadka 2024-11-29 16:18:17 +01:00
parent da337ba5fe
commit 638e1e3062
2 changed files with 24 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import sys
import yaml
from importlib.metadata import Distribution
from time import sleep
LOG = logging.getLogger(__name__)
@ -106,12 +107,24 @@ def galaxy_collection_install(requirements_file: str,
args += ["--requirements-file", requirements_file]
if force:
args += ["--force"]
try:
run_command("ansible-galaxy", args)
except subprocess.CalledProcessError as e:
LOG.error("Failed to install Ansible collections from %s via Ansible "
"Galaxy: returncode %d", requirements_file, e.returncode)
sys.exit(e.returncode)
for retry_count in range(1, 6):
try:
run_command("ansible-galaxy", args)
except subprocess.CalledProcessError as e:
if retry_count < 5:
LOG.warning(f"Failed to install Ansible collections from "
f"{requirements_file} using Ansible Galaxy "
f"(error: {e}) (retry: {retry_count}/5)")
sleep(2)
continue
else:
LOG.error(f"Failed to install Ansible collections from "
f"{requirements_file} using Ansible Galaxy "
f"(error: {e}) after 5 retries")
LOG.error("Exiting")
sys.exit(e.returncode)
break
def read_file(path: os.path, mode: str = "r") -> str | bytes:

View File

@ -0,0 +1,5 @@
---
features:
- |
``kolla-ansible install-deps`` subcommand will now retry on Ansible Galaxy
collections installation failures.