mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-26 21:33:05 +00:00
New utils/facts.py: Provide facts about the repo like role and module lists
The list of modules and roles is needed in several scripts now,
therefore it makes sense to have one place for this.
Here are the current variables:
BASE_DIR: Base directory of the repo
ROLES: List of roles in the roles folder
MANAGEMENT_MODULES: List of management modules in the plugins/modules
folder
ROLES_MODULES: List of modules in the roles/*/library folders
ALL_MODULES: List of all modules, the management and the roles
modules
All lists are sorted.
This commit is contained in:
41
utils/facts.py
Normal file
41
utils/facts.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def get_roles(dir):
|
||||||
|
roles = []
|
||||||
|
|
||||||
|
_rolesdir = "%s/roles/" % dir
|
||||||
|
for _role in os.listdir(_rolesdir):
|
||||||
|
_roledir = "%s/%s" % (_rolesdir, _role)
|
||||||
|
if not os.path.isdir(_roledir) or \
|
||||||
|
not os.path.isdir("%s/meta" % _roledir) or \
|
||||||
|
not os.path.isdir("%s/tasks" % _roledir):
|
||||||
|
continue
|
||||||
|
roles.append(_role)
|
||||||
|
|
||||||
|
return sorted(roles)
|
||||||
|
|
||||||
|
|
||||||
|
def get_modules(dir):
|
||||||
|
management_modules = []
|
||||||
|
roles_modules = []
|
||||||
|
|
||||||
|
for root, _dirs, files in os.walk(dir):
|
||||||
|
if not root.startswith("%s/plugins/" % dir) and \
|
||||||
|
not root.startswith("%s/roles/" % dir):
|
||||||
|
continue
|
||||||
|
for _file in files:
|
||||||
|
if _file.endswith(".py"):
|
||||||
|
if root == "%s/plugins/modules" % dir:
|
||||||
|
management_modules.append(_file[:-3])
|
||||||
|
elif root.startswith("%s/roles/" % dir):
|
||||||
|
if root.endswith("/library"):
|
||||||
|
roles_modules.append(_file[:-3])
|
||||||
|
|
||||||
|
return sorted(management_modules), sorted(roles_modules)
|
||||||
|
|
||||||
|
|
||||||
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__) + "/..")
|
||||||
|
ROLES = get_roles(BASE_DIR)
|
||||||
|
MANAGEMENT_MODULES, ROLES_MODULES = get_modules(BASE_DIR)
|
||||||
|
ALL_MODULES = sorted(MANAGEMENT_MODULES + ROLES_MODULES)
|
||||||
Reference in New Issue
Block a user