|
|
@ -13,7 +13,7 @@ import json
|
|
|
|
|
|
|
|
|
|
|
|
from os.path import expanduser
|
|
|
|
from os.path import expanduser
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
|
|
|
from ansible.module_utils.ansible_release import __version__ as ANSIBLE_VERSION
|
|
|
|
from ansible.module_utils.ansible_release import __version__ as ANSIBLE_VERSION
|
|
|
|
from ansible.module_utils.six.moves import configparser
|
|
|
|
from ansible.module_utils.six.moves import configparser
|
|
|
|
import ansible.module_utils.six.moves.urllib.parse as urlparse
|
|
|
|
import ansible.module_utils.six.moves.urllib.parse as urlparse
|
|
|
@ -99,6 +99,7 @@ AZURE_FAILED_STATE = "Failed"
|
|
|
|
HAS_AZURE = True
|
|
|
|
HAS_AZURE = True
|
|
|
|
HAS_AZURE_EXC = None
|
|
|
|
HAS_AZURE_EXC = None
|
|
|
|
HAS_AZURE_CLI_CORE = True
|
|
|
|
HAS_AZURE_CLI_CORE = True
|
|
|
|
|
|
|
|
HAS_AZURE_CLI_CORE_EXC = None
|
|
|
|
|
|
|
|
|
|
|
|
HAS_MSRESTAZURE = True
|
|
|
|
HAS_MSRESTAZURE = True
|
|
|
|
HAS_MSRESTAZURE_EXC = None
|
|
|
|
HAS_MSRESTAZURE_EXC = None
|
|
|
@ -114,16 +115,16 @@ try:
|
|
|
|
from packaging.version import Version
|
|
|
|
from packaging.version import Version
|
|
|
|
HAS_PACKAGING_VERSION = True
|
|
|
|
HAS_PACKAGING_VERSION = True
|
|
|
|
HAS_PACKAGING_VERSION_EXC = None
|
|
|
|
HAS_PACKAGING_VERSION_EXC = None
|
|
|
|
except ImportError as exc:
|
|
|
|
except ImportError:
|
|
|
|
Version = None
|
|
|
|
Version = None
|
|
|
|
HAS_PACKAGING_VERSION = False
|
|
|
|
HAS_PACKAGING_VERSION = False
|
|
|
|
HAS_PACKAGING_VERSION_EXC = exc
|
|
|
|
HAS_PACKAGING_VERSION_EXC = traceback.format_exc()
|
|
|
|
|
|
|
|
|
|
|
|
# NB: packaging issue sometimes cause msrestazure not to be installed, check it separately
|
|
|
|
# NB: packaging issue sometimes cause msrestazure not to be installed, check it separately
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from msrest.serialization import Serializer
|
|
|
|
from msrest.serialization import Serializer
|
|
|
|
except ImportError as exc:
|
|
|
|
except ImportError:
|
|
|
|
HAS_MSRESTAZURE_EXC = exc
|
|
|
|
HAS_MSRESTAZURE_EXC = traceback.format_exc()
|
|
|
|
HAS_MSRESTAZURE = False
|
|
|
|
HAS_MSRESTAZURE = False
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -161,7 +162,7 @@ try:
|
|
|
|
from azure.mgmt.containerregistry import ContainerRegistryManagementClient
|
|
|
|
from azure.mgmt.containerregistry import ContainerRegistryManagementClient
|
|
|
|
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
|
|
|
|
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
|
|
|
|
except ImportError as exc:
|
|
|
|
except ImportError as exc:
|
|
|
|
HAS_AZURE_EXC = exc
|
|
|
|
HAS_AZURE_EXC = traceback.format_exc()
|
|
|
|
HAS_AZURE = False
|
|
|
|
HAS_AZURE = False
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -170,6 +171,7 @@ try:
|
|
|
|
from azure.common.cloud import get_cli_active_cloud
|
|
|
|
from azure.common.cloud import get_cli_active_cloud
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
HAS_AZURE_CLI_CORE = False
|
|
|
|
HAS_AZURE_CLI_CORE = False
|
|
|
|
|
|
|
|
HAS_AZURE_CLI_CORE_EXC = None
|
|
|
|
CLIError = Exception
|
|
|
|
CLIError = Exception
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -266,16 +268,16 @@ class AzureRMModuleBase(object):
|
|
|
|
required_if=merged_required_if)
|
|
|
|
required_if=merged_required_if)
|
|
|
|
|
|
|
|
|
|
|
|
if not HAS_PACKAGING_VERSION:
|
|
|
|
if not HAS_PACKAGING_VERSION:
|
|
|
|
self.fail("Do you have packaging installed? Try `pip install packaging`"
|
|
|
|
self.fail(msg=missing_required_lib('packaging'),
|
|
|
|
"- {0}".format(HAS_PACKAGING_VERSION_EXC))
|
|
|
|
exception=HAS_PACKAGING_VERSION_EXC)
|
|
|
|
|
|
|
|
|
|
|
|
if not HAS_MSRESTAZURE:
|
|
|
|
if not HAS_MSRESTAZURE:
|
|
|
|
self.fail("Do you have msrestazure installed? Try `pip install msrestazure`"
|
|
|
|
self.fail(msg=missing_required_lib('msrestazure'),
|
|
|
|
"- {0}".format(HAS_MSRESTAZURE_EXC))
|
|
|
|
exception=HAS_MSRESTAZURE_EXC)
|
|
|
|
|
|
|
|
|
|
|
|
if not HAS_AZURE:
|
|
|
|
if not HAS_AZURE:
|
|
|
|
self.fail("Do you have azure>={1} installed? Try `pip install ansible[azure]`"
|
|
|
|
self.fail(msg=missing_required_lib('ansible[azure] (azure >= {0})'.format(AZURE_MIN_RELEASE)),
|
|
|
|
"- {0}".format(HAS_AZURE_EXC, AZURE_MIN_RELEASE))
|
|
|
|
exception=HAS_AZURE_EXC)
|
|
|
|
|
|
|
|
|
|
|
|
self._network_client = None
|
|
|
|
self._network_client = None
|
|
|
|
self._storage_client = None
|
|
|
|
self._storage_client = None
|
|
|
@ -1146,7 +1148,8 @@ class AzureRMAuth(object):
|
|
|
|
|
|
|
|
|
|
|
|
if auth_source == 'cli':
|
|
|
|
if auth_source == 'cli':
|
|
|
|
if not HAS_AZURE_CLI_CORE:
|
|
|
|
if not HAS_AZURE_CLI_CORE:
|
|
|
|
self.fail("Azure auth_source is `cli`, but azure-cli package is not available. Try `pip install azure-cli --upgrade`")
|
|
|
|
self.fail(msg=missing_required_lib('azure-cli', reason='for `cli` auth_source'),
|
|
|
|
|
|
|
|
exception=HAS_AZURE_CLI_CORE_EXC)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.log('Retrieving credentials from Azure CLI profile')
|
|
|
|
self.log('Retrieving credentials from Azure CLI profile')
|
|
|
|
cli_credentials = self._get_azure_cli_credentials()
|
|
|
|
cli_credentials = self._get_azure_cli_credentials()
|
|
|
|