From d438dd31f4a0db2c75cc029efddd208782630c28 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Mon, 11 Aug 2014 10:05:40 -0500 Subject: [PATCH] Make VMWare script less willing to set client to None. --- awx/plugins/inventory/vmware.py | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/awx/plugins/inventory/vmware.py b/awx/plugins/inventory/vmware.py index 7e17e4d10b..5c75eece55 100755 --- a/awx/plugins/inventory/vmware.py +++ b/awx/plugins/inventory/vmware.py @@ -200,21 +200,33 @@ if __name__ == '__main__': config.read(configfilename) break - try: - client = Client( - os.environ.get('VMWARE_HOST', config.get('auth','host')), - os.environ.get('VMWARE_USER', config.get('auth','user')), - os.environ.get('VMWARE_PASSWORD', config.get('auth','password')), - ) - except Exception, e: - client = None - #print >> STDERR "Unable to login (only cache avilable): %s", str(e) + auth_host, auth_user, auth_password = None, None, None - # acitually do the work + # Read our authentication information from the INI file, if it exists. + try: + auth_host = config.get('auth', 'host') + auth_user = config.get('auth', 'user') + auth_password = config.get('auth', 'password') + except Exception: + pass + + # If any of the VMWare environment variables are set, they trump + # the INI configuration. + if 'VMWARE_HOST' in os.environ: + auth_host = os.environ['VMWARE_HOST'] + if 'VMWARE_USER' in os.environ: + auth_user = os.environ['VMWARE_USER'] + if 'VMWARE_PASSWORD' in os.environ: + auth_password = os.environ['VMWARE_PASSWORD'] + + # Create the VMWare client. + client = Client(auth_host, auth_user, auth_password) + + # Actually do the work. if hostname is None: inventory = get_inventory(client, config) else: inventory = get_single_host(client, config, hostname) - # return to ansible + # Return to Ansible. print inventory