From 3f50caca172be90458cc50e034ac00aad95cb2aa Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Jan 19 2018 22:27:38 +0000 Subject: bin/get_roles.py: replace the with-base with --append flag this way we can pass multiple roles that we want to be shown at the results. Change also the usage of with-base with append on the test_roles script --- diff --git a/bin/get_roles.py b/bin/get_roles.py index d5a4386..69f8ed3 100755 --- a/bin/get_roles.py +++ b/bin/get_roles.py @@ -6,6 +6,7 @@ import argparse import yaml import os + def read_file_skip_jinja(filename): ''' reads a file and returns its content, except lines starting with '{%' ''' non_jinja_lines = [] @@ -30,10 +31,8 @@ def get_roles_of_one_server(server): return roles -def get_roles(with_base=False): - roles = [] - if with_base: - roles.append('base') +def get_roles(append=[]): + roles = append for sls in os.listdir('pillar/id'): _roles = get_roles_of_one_server(sls) @@ -47,10 +46,15 @@ def get_roles(with_base=False): def print_roles(): parser = argparse.ArgumentParser('Collects all the roles that are assigned to a minion, and returns them as a python array, a yaml list or a plain list (parsable by bash)') parser.add_argument('-o', '--out', choices=['bash', 'python', 'yaml'], help='Select different output format. Options: bash (default), python, yaml') - parser.add_argument('-b', '--with-base', action='store_true', default=False, help='Include the base role at the results') + parser.add_argument('-a', '--append', action='append', nargs='+', help='Append a list of given roles at the results.') args = parser.parse_args() - roles = get_roles(with_base=args.with_base) + appended = [] + if args.append: + for sublist in args.append: + for item in sublist: + appended.append(item) + roles = get_roles(append=appended) if args.out == 'python': print(roles) elif args.out == 'yaml': diff --git a/bin/test_roles.py b/bin/test_roles.py index af0c149..605630a 100755 --- a/bin/test_roles.py +++ b/bin/test_roles.py @@ -8,8 +8,7 @@ import sys from get_roles import get_roles status = 0 - -roles = get_roles(with_base=True) +roles = get_roles(append=['base']) for directory in ['salt', 'pillar']: for sls in os.listdir('%s/role' % directory):