| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
DOCUMENTATION = ''' |
| 9 |
--- |
| 10 |
module: azure_rm_ml_compute_info |
| 11 |
version_added: "3.15.0" |
| 12 |
short_description: List ML Compute resources |
| 13 |
description: |
| 14 |
- List ML Compute resources. |
| 15 |
options: |
| 16 |
name: |
| 17 |
description: |
| 18 |
- Name of the Azure ML compute. |
| 19 |
type: str |
| 20 |
required: false |
| 21 |
resource_group: |
| 22 |
description: |
| 23 |
- Name of resource group. |
| 24 |
required: true |
| 25 |
type: str |
| 26 |
ml_workspace: |
| 27 |
description: |
| 28 |
- Name of the Azure ML workspace. |
| 29 |
required: true |
| 30 |
type: str |
| 31 |
type: |
| 32 |
description: |
| 33 |
- The type of compute target. |
| 34 |
choices: |
| 35 |
- amlcompute |
| 36 |
- computeinstance |
| 37 |
required: false |
| 38 |
type: str |
| 39 |
|
| 40 |
extends_documentation_fragment: |
| 41 |
- azure.azcollection.azure |
| 42 |
|
| 43 |
author: |
| 44 |
- Bill Peck (@p3ck) |
| 45 |
''' |
| 46 |
|
| 47 |
EXAMPLES = ''' |
| 48 |
- name: List ML Compute |
| 49 |
azure.azcollection.azure_rm_ml_compute_info: |
| 50 |
name: MyCompute |
| 51 |
resource_group: myResourceGroup |
| 52 |
ml_workspace: myMLWorkspace |
| 53 |
|
| 54 |
- name: List ML Compute |
| 55 |
azure.azcollection.azure_rm_ml_compute_info: |
| 56 |
resource_group: myResourceGroup |
| 57 |
ml_workspace: myMLWorkspace |
| 58 |
type: amlcompute |
| 59 |
''' |
| 60 |
|
| 61 |
RETURN = ''' |
| 62 |
ml_computes: |
| 63 |
description: |
| 64 |
- Compute that was just created or updated. |
| 65 |
returned: always |
| 66 |
type: dict |
| 67 |
sample: [ |
| 68 |
{ |
| 69 |
"description": "Compute Integration Tests", |
| 70 |
"enable_node_public_ip": true, |
| 71 |
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-compute/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxx-xxx/computes/amlxxxxxxx-xxxcomp", |
| 72 |
"idle_time_before_scale_down": 120, |
| 73 |
"location": "eastus", |
| 74 |
"max_instances": 200, |
| 75 |
"min_instances": 0, |
| 76 |
"name": "amlxxxxxxx-xxxcomp", |
| 77 |
"network_settings": {}, |
| 78 |
"provisioning_state": "Succeeded", |
| 79 |
"size": "STANDARD_DS3_V2", |
| 80 |
"ssh_public_access_enabled": true, |
| 81 |
"tags": {"created_by": "Ansible"}, |
| 82 |
"tier": "dedicated", |
| 83 |
"type": "amlcompute" |
| 84 |
}, |
| 85 |
{ |
| 86 |
"created_on": "2026-02-16T19:08:51.821821+0000", |
| 87 |
"description": "Compute Integration Tests", |
| 88 |
"enable_node_public_ip": true, |
| 89 |
"enable_os_patching": false, |
| 90 |
"enable_root_access": true, |
| 91 |
"enable_sso": true, |
| 92 |
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-compute/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxx-xxx/computes/compxxxxxxx-xxxinst", |
| 93 |
"identity": { |
| 94 |
"principal_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 95 |
"tenant_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 96 |
"type": "system_assigned" |
| 97 |
}, |
| 98 |
"last_operation": { |
| 99 |
"operation_name": "Stop", |
| 100 |
"operation_status": "Succeeded", |
| 101 |
"operation_time": "2026-02-16T19:12:01.237Z", |
| 102 |
"operation_trigger": "User" |
| 103 |
}, |
| 104 |
"location": "eastus", |
| 105 |
"name": "compxxxxxxx-xxxinst", |
| 106 |
"network_settings": { |
| 107 |
"private_ip_address": "10.0.0.4", |
| 108 |
"public_ip_address": "xx.xxx.xxx.xxx" |
| 109 |
}, |
| 110 |
"os_image_metadata": { |
| 111 |
"current_image_version": "26.01.05", |
| 112 |
"is_latest_os_image_version": true, |
| 113 |
"latest_image_version": "26.01.05" |
| 114 |
}, |
| 115 |
"provisioning_state": "Succeeded", |
| 116 |
"release_quota_on_stop": false, |
| 117 |
"services": [ |
| 118 |
{ |
| 119 |
"display_name": "Jupyter", |
| 120 |
"endpoint_uri": "https://compxxxxxxx-xxxinst.eastus.instances.azureml.ms/tree/" |
| 121 |
}, |
| 122 |
{ |
| 123 |
"display_name": "Jupyter Lab", |
| 124 |
"endpoint_uri": "https://compxxxxxxx-xxxinst.eastus.instances.azureml.ms/lab" |
| 125 |
} |
| 126 |
], |
| 127 |
"size": "Standard_DS3_v2", |
| 128 |
"ssh_public_access_enabled": false, |
| 129 |
"ssh_settings": { |
| 130 |
"admin_username": "azureuser", |
| 131 |
"ssh_key_value": "ssh-rsa AAAAB........PLp/ administrator@xxxxxx-xxxxxxx", |
| 132 |
"ssh_port": "50000" |
| 133 |
}, |
| 134 |
"state": "Stopped", |
| 135 |
"tags": { |
| 136 |
"created_by": "Ansible" |
| 137 |
}, |
| 138 |
"type": "computeinstance" |
| 139 |
} |
| 140 |
] |
| 141 |
''' |
| 142 |
|
| 143 |
|
| 144 |
try: |
| 145 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ml import MLClientCommon |
| 146 |
from azure.core.exceptions import ResourceNotFoundError |
| 147 |
except ImportError: |
| 148 |
|
| 149 |
pass |
| 150 |
|
| 151 |
|
| 152 |
class AzureRMMLComputeInfo(MLClientCommon): |
| 153 |
def __init__(self): |
| 154 |
|
| 155 |
self.module_arg_spec = dict( |
| 156 |
name=dict( |
| 157 |
type='str', |
| 158 |
required=False, |
| 159 |
), |
| 160 |
resource_group=dict( |
| 161 |
type='str', |
| 162 |
required=True, |
| 163 |
), |
| 164 |
ml_workspace=dict( |
| 165 |
type='str', |
| 166 |
required=True, |
| 167 |
), |
| 168 |
type=dict( |
| 169 |
type='str', |
| 170 |
required=False, |
| 171 |
choices=['amlcompute', 'computeinstance'], |
| 172 |
), |
| 173 |
) |
| 174 |
|
| 175 |
self._client = None |
| 176 |
self.ml_compute = None |
| 177 |
self.ml_registry = None |
| 178 |
|
| 179 |
self.results = dict( |
| 180 |
ml_computes=[] |
| 181 |
) |
| 182 |
|
| 183 |
super(AzureRMMLComputeInfo, self).__init__(self.module_arg_spec, |
| 184 |
supports_tags=False, |
| 185 |
supports_check_mode=True, |
| 186 |
facts_module=True, |
| 187 |
) |
| 188 |
|
| 189 |
def exec_module(self, **kwargs): |
| 190 |
|
| 191 |
for key in list(self.module_arg_spec.keys()): |
| 192 |
setattr(self, key, kwargs[key]) |
| 193 |
|
| 194 |
if self.name: |
| 195 |
try: |
| 196 |
result = self.client.compute.get(self.name) |
| 197 |
ml_computes = [self.entity_to_dict(result)] |
| 198 |
except ResourceNotFoundError: |
| 199 |
ml_computes = [] |
| 200 |
else: |
| 201 |
results = self.client.compute.list(compute_type=self.type) |
| 202 |
ml_computes = [self.entity_to_dict(x) for x in results] |
| 203 |
|
| 204 |
self.results['ml_computes'] = ml_computes |
| 205 |
return self.results |
| 206 |
|
| 207 |
|
| 208 |
def main(): |
| 209 |
AzureRMMLComputeInfo() |
| 210 |
|
| 211 |
|
| 212 |
if __name__ == '__main__': |
| 213 |
main() |