From c1a30c743eb810fbefe1dc314277931fa33842b3 Mon Sep 17 00:00:00 2001 From: Youhua Li Date: Fri, 30 Nov 2018 04:06:05 -0800 Subject: [PATCH] enable ONE auth file authentication (#49331) --- lib/ansible/modules/cloud/opennebula/one_vm.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/opennebula/one_vm.py b/lib/ansible/modules/cloud/opennebula/one_vm.py index 336067ad769..98794772f4b 100644 --- a/lib/ansible/modules/cloud/opennebula/one_vm.py +++ b/lib/ansible/modules/cloud/opennebula/one_vm.py @@ -52,6 +52,9 @@ options: description: - Password of the user to login into OpenNebula RPC server. If not set - then the value of the C(ONE_PASSWORD) environment variable is used. + - if both I(api_username) or I(api_password) are not set, then it will try + - authenticate with ONE auth file. Default path is "~/.one/one_auth". + - Set environment variable C(ONE_AUTH) to override this path. template_name: description: - Name of VM template to use to create a new instace @@ -1220,8 +1223,8 @@ def get_connection_info(module): if not password: password = os.environ.get('ONE_PASSWORD') - if not(url and username and password): - module.fail_json(msg="One or more connection parameters (api_url, api_username, api_password) were not specified") + if not url: + module.fail_json(msg="Opennebula API url (api_url) is not specified") from collections import namedtuple auth_params = namedtuple('auth', ('url', 'username', 'password')) @@ -1309,7 +1312,10 @@ def main(): count_labels = params.get('count_labels') disk_saveas = params.get('disk_saveas') - client = oca.Client(auth.username + ':' + auth.password, auth.url) + if not (auth.username and auth.password): + client = oca.Client(None, auth.url) + else: + client = oca.Client(auth.username + ':' + auth.password, auth.url) if attributes: attributes = dict((key.upper(), value) for key, value in attributes.items())