From 442ff683d1e5b3c15a7ef90b27c4be2b3e70ff30 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sat, 21 Jan 2023 14:52:48 +0100 Subject: roles.py: support nested roles + cli invocation - walk both pillar and salt roles - support nested roles / state files in subdirectories - allow test invocation of the script from the command line Signed-off-by: Georg Pfuetzenreuter --- bin/roles.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/roles.py b/bin/roles.py index 1777f8c..32de0cf 100755 --- a/bin/roles.py +++ b/bin/roles.py @@ -6,8 +6,13 @@ roles = [] excluded = ['common-suse', 'minion'] def get(): - for file in os.listdir('salt/role'): - role = os.path.splitext(file)[0] - if not role in excluded: - roles.append(role) + for root in ['pillar', 'salt']: + for rootdir, subdirs, files in os.walk(os.path.join(root, 'role')): + for file in files: + role = os.path.splitext(file)[0] + if not role in excluded and not role in roles: + roles.append(role) return roles + +if __name__ == '__main__': + print(get()) -- cgit v1.2.3