Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authentication via params and env variables. #16559

Merged
merged 1 commit into from
Jul 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docsite/rst/guide_azure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Requirements
------------

Using the Azure Resource Manager modules requires having `Azure Python SDK <https://github.com/Azure/azure-sdk-for-python>`_
installed on the host running Ansible. You will need to have >= v2.0.0RC4 installed. The simplest way to install the
installed on the host running Ansible. You will need to have == v2.0.0RC5 installed. The simplest way to install the
SDK is via pip:

.. code-block:: bash

$ pip install "azure>=2.0.0rc4"
$ pip install "azure==2.0.0rc5"


Authenticating with Azure
Expand Down
12 changes: 6 additions & 6 deletions lib/ansible/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,21 @@ def _get_profile(self, profile="default"):
except:
pass

if credentials.get('client_id') is not None or credentials.get('ad_user') is not None:
if credentials.get('subscription_id'):
return credentials

return None

def _get_env_credentials(self):
env_credentials = dict()
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.iteritems():
env_credentials[attribute] = os.environ.get(env_variable, None)

if env_credentials['profile'] is not None:
if env_credentials['profile']:
credentials = self._get_profile(env_credentials['profile'])
return credentials

if env_credentials['client_id'] is not None:
if env_credentials.get('subscription_id') is not None:
return env_credentials

return None
Expand All @@ -338,7 +338,7 @@ def _get_credentials(self, params):
self.log('Getting credentials')

arg_credentials = dict()
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.items():
for attribute, env_variable in AZURE_CREDENTIAL_ENV_MAPPING.iteritems():
arg_credentials[attribute] = params.get(attribute, None)

# try module params
Expand All @@ -347,7 +347,7 @@ def _get_credentials(self, params):
credentials = self._get_profile(arg_credentials['profile'])
return credentials

if arg_credentials['client_id'] is not None:
if arg_credentials['subscription_id']:
self.log('Received credentials from parameters.')
return arg_credentials

Expand Down