Added gid to applications to make them posix group ldap compatible

This commit is contained in:
2025-07-03 23:51:14 +02:00
parent a93e1520d4
commit 56b3f854c5
10 changed files with 141 additions and 27 deletions

View File

@@ -0,0 +1,42 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import yaml
from ansible.plugins.lookup import LookupBase
from ansible.errors import AnsibleError
class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
application_id = terms[0]
base_gid = kwargs.get('base_gid', 10000)
roles_dir = kwargs.get('roles_dir', 'roles')
if not os.path.isdir(roles_dir):
raise AnsibleError(f"Roles directory '{roles_dir}' not found")
matched_roles = []
for root, dirs, files in os.walk(roles_dir):
if os.path.basename(root) == "vars" and "main.yml" in files:
vars_path = os.path.join(root, "main.yml")
try:
with open(vars_path, 'r') as f:
data = yaml.safe_load(f) or {}
app_id = data.get('application_id')
if app_id:
matched_roles.append((app_id, vars_path))
except Exception as e:
raise AnsibleError(f"Error parsing {vars_path}: {e}")
# sort alphabetically by application_id
sorted_ids = sorted(app_id for app_id, _ in matched_roles)
try:
index = sorted_ids.index(application_id)
except ValueError:
raise AnsibleError(f"Application ID '{application_id}' not found in any role")
return [base_gid + index]