From 588b67b7ffdc0ce6b146e2212111dcb1108417e9 Mon Sep 17 00:00:00 2001 From: David Vallee Delisle Date: Fri, 29 Jan 2021 18:03:47 -0500 Subject: [PATCH] More detail in arg validation There's no reason to forbid --list and --static-yaml-inventory Also, we should return an error if both --list and --host are defined. Change-Id: I94393de4a71a92c12f8d427748853d7ff2ce5a02 (cherry picked from commit 040fd0486e123e5490fe42007194bb9c11a4087f) --- scripts/tripleo-ansible-inventory | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/tripleo-ansible-inventory b/scripts/tripleo-ansible-inventory index 747b450b3..29bd85c2c 100755 --- a/scripts/tripleo-ansible-inventory +++ b/scripts/tripleo-ansible-inventory @@ -88,6 +88,13 @@ def _parse_config(): 'variable missing or --os-cloud option is not set, ' 'unable to proceed.', file=sys.stderr) sys.exit(1) + if (configs.static_yaml_inventory or configs.list) and configs.host: + print( + "ERROR: can't list (--list) all hosts or generate an inventory " + "(--static-yaml-inventory) while looking for a specific host " + "(--host)" + ) + sys.exit(1) if configs.auth_url: if '/v2.0' in configs.auth_url: configs.auth_url = configs.auth_url.replace('/v2.0', '/v3') @@ -216,7 +223,9 @@ def main(): if configs.debug: traceback.print_exc() sys.exit(1) - elif configs.static_yaml_inventory: + elif configs.host: + print(json.dumps(inventory.host())) + if configs.static_yaml_inventory: try: inventory.write_static_inventory(configs.static_yaml_inventory) except Exception as e: @@ -225,8 +234,6 @@ def main(): if configs.debug: traceback.print_exc() sys.exit(1) - elif configs.host: - print(json.dumps(inventory.host())) sys.exit(0)