Restructured users

This commit is contained in:
2025-07-09 02:26:50 +02:00
parent 22b4342300
commit ed0cd9b8c0
19 changed files with 27 additions and 13 deletions

View File

@@ -21,7 +21,7 @@ def load_run_after(meta_file):
def load_application_id(role_path):
"""Load the application_id from the vars/main.yml of the role."""
vars_file = os.path.join(role_path, 'main', 'main.yml')
vars_file = os.path.join(role_path, 'vars', 'main.yml')
if os.path.exists(vars_file):
with open(vars_file, 'r') as f:
data = yaml.safe_load(f) or {}
@@ -113,14 +113,21 @@ def generate_playbook_entries(roles_dir, prefix=None):
entries = []
for role_name in sorted_role_names:
role = roles[role_name]
# --- new validation block ---
if role.get('application_id') is None:
raise ValueError(f"Role '{role_name}' is missing an application_id")
# ----------------------------
app_id = role['application_id']
entries.append(
f"- name: setup {role['application_id']}\n"
f" when: ('{role['application_id']}' | application_allowed(group_names, allowed_applications))\n"
f"- name: setup {app_id}\n"
f" when: ('{app_id}' | application_allowed(group_names, allowed_applications))\n"
f" include_role:\n"
f" name: {role['role_name']}\n"
)
entries.append(
f"- name: flush handlers after {role['application_id']}\n"
f"- name: flush handlers after {app_id}\n"
f" meta: flush_handlers\n"
)

View File

@@ -110,7 +110,7 @@ def build_users(defs, primary_domain, start_id, become_pwd):
def load_user_defs(roles_directory):
"""
Scan all roles/*/meta/users.yml files and merge any 'users:' sections.
Scan all roles/*/users/main.yml files and merge any 'users:' sections.
Args:
roles_directory (str): Path to the directory containing role subdirectories.
@@ -121,7 +121,7 @@ def load_user_defs(roles_directory):
Raises:
ValueError: On invalid format or conflicting override values.
"""
pattern = os.path.join(roles_directory, '*/meta/users.yml')
pattern = os.path.join(roles_directory, '*/users/main.yml')
files = sorted(glob.glob(pattern))
merged = OrderedDict()
@@ -165,11 +165,11 @@ def dictify(data):
def parse_args():
parser = argparse.ArgumentParser(
description='Generate a users.yml by merging all roles/*/meta/users.yml definitions.'
description='Generate a users.yml by merging all roles/*/users/main.yml definitions.'
)
parser.add_argument(
'--roles-dir', '-r', required=True,
help='Directory containing roles (e.g., roles/*/meta/users.yml).'
help='Directory containing roles (e.g., roles/*/users/main.yml).'
)
parser.add_argument(
'--output', '-o', required=True,