From a6ef48744639a3b76d63f7e31e75172223377678 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Dec 05 2017 09:54:24 +0000 Subject: bin/get_roles.py: use a -o --out option to specify the output format --- diff --git a/bin/get_roles.py b/bin/get_roles.py index 35353f6..8a5e553 100755 --- a/bin/get_roles.py +++ b/bin/get_roles.py @@ -39,15 +39,14 @@ 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('-p', '--python', action='store_true', default=False, help='Prints the roles as a python array') - parser.add_argument('-y', '--yaml', action='store_true', default=False, help='Prints the roles as a yaml array') + 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') args = parser.parse_args() roles = get_roles(with_base=args.with_base) - if args.python: + if args.out == 'python': print(roles) - elif args.yaml: + elif args.out == 'yaml': print('roles:') for role in roles: print(' - %s' % role) diff --git a/bin/prepare_test_show_highstate_env.sh b/bin/prepare_test_show_highstate_env.sh index 09f2133..2ddef0e 100755 --- a/bin/prepare_test_show_highstate_env.sh +++ b/bin/prepare_test_show_highstate_env.sh @@ -37,7 +37,7 @@ $SUDO rm -rf /srv/{salt,pillar} $SUDO ln -s $PWD/salt /srv/salt $SUDO ln -s $PWD/pillar /srv/pillar ID=$(hostname -f) -ROLES=$(bin/get_roles.py --yaml) +ROLES=$(bin/get_roles.py -o yaml) printf "city:\ncountry:\ndomain: infra.opensuse.org\nosfullname:\nosmajorrelease:\nosrelease_info:\n$ROLES\nsalt_cluster: opensuse\nvirt_cluster:\n" | $SUDO tee /etc/salt/grains > /dev/null touch pillar/id/${ID//./_}.sls [[ -n $STRIP_SECRETS ]] && sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $(grep -lr "\- secrets\." pillar)