roles.py: repair role walking

Improve nested role support introduced with
442ff683d1 by correctly converting
subdirectories into nested state references.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2023-01-21 19:40:19 +01:00
parent ab2f6802a9
commit 50c638a000
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57

View File

@ -8,10 +8,17 @@ excluded = ['common-suse', 'minion']
def get(): def get():
for root in ['pillar', 'salt']: for root in ['pillar', 'salt']:
for rootdir, subdirs, files in os.walk(os.path.join(root, 'role')): for rootdir, subdirs, files in os.walk(os.path.join(root, 'role')):
myrootdir = rootdir.split('/')
if len(myrootdir) > 2:
level = myrootdir[2:]
for file in files: for file in files:
role = os.path.splitext(file)[0] splitfile = os.path.splitext(file)
if not role in excluded and not role in roles: if len(splitfile) == 2 and splitfile[1] == '.sls':
roles.append(role) role = os.path.splitext(file)[0]
if len(myrootdir) > 2:
role = '.'.join(level) + '.' + role
if not role in excluded and not role in roles:
roles.append(role)
return roles return roles
if __name__ == '__main__': if __name__ == '__main__':