diff --git a/lib/ansible/modules/cloud/opennebula/one_vm.py b/lib/ansible/modules/cloud/opennebula/one_vm.py index 14c0b5feb6a..521dfe74295 100644 --- a/lib/ansible/modules/cloud/opennebula/one_vm.py +++ b/lib/ansible/modules/cloud/opennebula/one_vm.py @@ -1300,15 +1300,16 @@ def get_connection_info(module): if not username: if not password: authfile = os.environ.get('ONE_AUTH') - if authfile is not None: - try: - authstring = open(authfile, "r").read().rstrip() - username = authstring.split(":")[0] - password = authstring.split(":")[1] - except BaseException: - module.fail_json(msg="Could not read ONE_AUTH file") - else: - module.fail_json(msg="No Credentials are set") + if authfile is None: + authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth") + try: + authstring = open(authfile, "r").read().rstrip() + username = authstring.split(":")[0] + password = authstring.split(":")[1] + except (OSError, IOError): + module.fail_json(msg=("Could not find or read ONE_AUTH file at '%s'" % authfile)) + except Exception: + module.fail_json(msg=("Error occurs when read ONE_AUTH file at '%s'" % authfile)) if not url: module.fail_json(msg="Opennebula API url (api_url) is not specified") from collections import namedtuple