mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Restructured users
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user