Added application ids filter for easier partial deployment

This commit is contained in:
2025-07-04 21:52:37 +02:00
parent 9f1d153053
commit 52f467c15c
5 changed files with 114 additions and 3 deletions

View File

@@ -6,7 +6,8 @@ import os
import datetime
import sys
def run_ansible_playbook(inventory, playbook, modes, limit=None, password_file=None, verbose=0, skip_tests=False):
def run_ansible_playbook(inventory, playbook, modes, limit=None, allowed_applications=None, password_file=None, verbose=0, skip_tests=False):
start_time = datetime.datetime.now()
print(f"\n▶️ Script started at: {start_time.isoformat()}\n")
@@ -22,6 +23,15 @@ def run_ansible_playbook(inventory, playbook, modes, limit=None, password_file=N
if limit:
cmd.extend(["--limit", limit])
# Pass application IDs parameter as extra var if provided
if allowed_applications:
joined = ",".join(allowed_applications)
cmd.extend(["-e", f"allowed_applications={joined}"])
else:
# No IDs provided: execute all applications defined in the inventory
cmd.extend(["-e", "allowed_applications=all"])
# Pass other mode flags
for key, value in modes.items():
val = str(value).lower() if isinstance(value, bool) else str(value)
cmd.extend(["-e", f"{key}={val}"])
@@ -43,6 +53,7 @@ def run_ansible_playbook(inventory, playbook, modes, limit=None, password_file=N
duration = end_time - start_time
print(f"⏱️ Total execution time: {duration}\n")
def main():
script_dir = os.path.dirname(os.path.realpath(__file__))
parser = argparse.ArgumentParser(
@@ -99,6 +110,12 @@ def main():
"--skip-validation", action="store_true",
help="Skip inventory validation before deployment."
)
parser.add_argument(
"--id",
nargs="+",
default=[],
help="List of application_id's for partial deploy. If not set, all application IDs defined in the inventory will be executed."
)
parser.add_argument(
"-v", "--verbose", action="count", default=0,
help="Increase verbosity level. Multiple -v flags increase detail (e.g., -vvv for maximum log output)."
@@ -134,6 +151,7 @@ def main():
playbook=playbook_file,
modes=modes,
limit=args.limit,
allowed_applications=args.allowed_applications,
password_file=args.password_file,
verbose=args.verbose,
skip_tests=args.skip_tests

View File

@@ -115,7 +115,7 @@ def generate_playbook_entries(roles_dir, prefix=None):
role = roles[role_name]
entries.append(
f"- name: setup {role['application_id']}\n"
f" when: ('{role['application_id']}' in group_names)\n"
f" when: {role['application_id']} | application_allowed(group_names, allowed_applications)\n"
f" include_role:\n"
f" name: {role['role_name']}\n"
)