diff options
author | Georg Pfuetzenreuter | 2023-01-21 14:52:48 +0100 |
---|---|---|
committer | Georg Pfuetzenreuter | 2023-01-21 14:52:48 +0100 |
commit | 442ff683d1e5b3c15a7ef90b27c4be2b3e70ff30 (patch) | |
tree | 97c24b0078d8fdb8cd9d5c7ae3c0534ef9c7aaa4 | |
parent | 12f0a7bce0b2ed747a0a3e5e6df1d8e7104b8b33 (diff) | |
download | salt-442ff683d1e5b3c15a7ef90b27c4be2b3e70ff30.tar.gz salt-442ff683d1e5b3c15a7ef90b27c4be2b3e70ff30.tar.bz2 salt-442ff683d1e5b3c15a7ef90b27c4be2b3e70ff30.zip |
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>
-rwxr-xr-x | bin/roles.py | 13 |
1 files 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()) |