From 2f81a284142fd00e42201aa7ed2708a1c5fa51fd Mon Sep 17 00:00:00 2001 From: Peter Hoffmann Date: Fri, 14 Jul 2017 20:01:43 +0200 Subject: [PATCH] use tenant in UserPassCredentials if set (#20751) * use tenant in UserPassCredentials if set If you have multiple Tenants you need to set the tenant in https://github.com/Azure/msrestazure-for-python/blob/master/msrestazure/azure_active_directory.py otherwise the azure_rm.py call will fail. see: https://github.com/ansible/ansible/pull/20750 * fixed PEP8 failure --- lib/ansible/module_utils/azure_rm_common.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py index 1626d8b0884..54cca6478a0 100644 --- a/lib/ansible/module_utils/azure_rm_common.py +++ b/lib/ansible/module_utils/azure_rm_common.py @@ -185,7 +185,11 @@ class AzureRMModuleBase(object): secret=self.credentials['secret'], tenant=self.credentials['tenant']) elif self.credentials.get('ad_user') is not None and self.credentials.get('password') is not None: - self.azure_credentials = UserPassCredentials(self.credentials['ad_user'], self.credentials['password']) + tenant = self.credentials.get('tenant') + if tenant is not None: + self.azure_credentials = UserPassCredentials(self.credentials['ad_user'], self.credentials['password'], tenant=tenant) + else: + self.azure_credentials = UserPassCredentials(self.credentials['ad_user'], self.credentials['password']) else: self.fail("Failed to authenticate with provided credentials. Some attributes were missing. " "Credentials must include client_id, secret and tenant or ad_user and password.")