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 <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2023-01-21 14:52:48 +01:00
parent 12f0a7bce0
commit 442ff683d1
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57

View File

@ -6,8 +6,13 @@ roles = []
excluded = ['common-suse', 'minion'] excluded = ['common-suse', 'minion']
def get(): def get():
for file in os.listdir('salt/role'): for root in ['pillar', 'salt']:
role = os.path.splitext(file)[0] for rootdir, subdirs, files in os.walk(os.path.join(root, 'role')):
if not role in excluded: for file in files:
roles.append(role) role = os.path.splitext(file)[0]
if not role in excluded and not role in roles:
roles.append(role)
return roles return roles
if __name__ == '__main__':
print(get())