| 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_component_info |
| 11 |
version_added: "3.16.0" |
| 12 |
short_description: List ML Component resources |
| 13 |
description: |
| 14 |
- List ML Component resources. |
| 15 |
options: |
| 16 |
name: |
| 17 |
description: |
| 18 |
- Name of the Azure ML component. |
| 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 |
ml_registry: |
| 32 |
description: |
| 33 |
- If provided, the command will target the registry |
| 34 |
instead of a workspace. Hence resource group and |
| 35 |
workspace won't be required. Must be provided if |
| 36 |
ml_workspace and resource_group are not provided. |
| 37 |
required: false |
| 38 |
type: str |
| 39 |
version: |
| 40 |
description: |
| 41 |
- Version of the data asset. Must be provided, if label |
| 42 |
is not provided. Mutually exclusive with label. |
| 43 |
required: false |
| 44 |
type: str |
| 45 |
label: |
| 46 |
description: |
| 47 |
- Label of the data asset. Must be provided, if version |
| 48 |
is not provided. Mutually exclusive with version. |
| 49 |
required: false |
| 50 |
type: str |
| 51 |
list_type: |
| 52 |
description: |
| 53 |
- Specify if you want active, archived or all datasets. |
| 54 |
type: str |
| 55 |
choices: |
| 56 |
- active |
| 57 |
- archived |
| 58 |
- all |
| 59 |
|
| 60 |
extends_documentation_fragment: |
| 61 |
- azure.azcollection.azure |
| 62 |
|
| 63 |
author: |
| 64 |
- Bill Peck (@p3ck) |
| 65 |
''' |
| 66 |
|
| 67 |
EXAMPLES = ''' |
| 68 |
- name: List ML Components |
| 69 |
azure.azcollection.azure_rm_ml_component_info: |
| 70 |
name: MyComponent |
| 71 |
resource_group: myResourceGroup |
| 72 |
ml_workspace: myMLWorkspace |
| 73 |
|
| 74 |
- name: List ML Components |
| 75 |
azure.azcollection.azure_rm_ml_component_info: |
| 76 |
resource_group: myResourceGroup |
| 77 |
ml_workspace: myMLWorkspace |
| 78 |
''' |
| 79 |
|
| 80 |
RETURN = ''' |
| 81 |
ml_components: |
| 82 |
description: |
| 83 |
- Components that match the query. |
| 84 |
returned: always |
| 85 |
type: dict |
| 86 |
sample: [ |
| 87 |
{ |
| 88 |
"$schema": "https://azuremlschemas.azureedge.net/latest/commandComponent.schema.json", |
| 89 |
"code": "azureml:/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-component/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxxxxx/codes/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/versions/1", |
| 90 |
"command": "python train.py --training_data ${{inputs.training_data}} --max_epocs ${{inputs.max_epocs}} --learning_rate ${{inputs.learning_rate}} --learning_rate_schedule ${{inputs.learning_rate_schedule}} --model_output ${{outputs.model_output}}", |
| 91 |
"creation_context": { |
| 92 |
"created_at": "2026-03-18T14:02:54.635544+00:00", |
| 93 |
"created_by": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 94 |
"created_by_type": "Application", |
| 95 |
"last_modified_at": "2026-03-18T14:02:54.773038+00:00", |
| 96 |
"last_modified_by": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 97 |
"last_modified_by_type": "Application" |
| 98 |
}, |
| 99 |
"display_name": "Train_upper_case", |
| 100 |
"environment": "azureml://registries/azureml/environments/sklearn-1.5/versions/41", |
| 101 |
"id": "azureml:/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-component/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxxxxx/components/componentxxxxxxxxxx/labels/default", |
| 102 |
"inputs": { |
| 103 |
"learning_rate": { |
| 104 |
"default": "0.01", |
| 105 |
"optional": false, |
| 106 |
"type": "number" |
| 107 |
}, |
| 108 |
"learning_rate_schedule": { |
| 109 |
"default": "time-based", |
| 110 |
"enum": [ |
| 111 |
"step", |
| 112 |
"time-based" |
| 113 |
], |
| 114 |
"optional": false, |
| 115 |
"type": "string" |
| 116 |
}, |
| 117 |
"max_epocs": { |
| 118 |
"max": "100", |
| 119 |
"min": "0", |
| 120 |
"optional": false, |
| 121 |
"type": "integer" |
| 122 |
}, |
| 123 |
"training_data": { |
| 124 |
"optional": false, |
| 125 |
"type": "uri_folder" |
| 126 |
} |
| 127 |
}, |
| 128 |
"is_deterministic": true, |
| 129 |
"name": "componentxxxxxxxxxx", |
| 130 |
"outputs": { |
| 131 |
"model_output": { |
| 132 |
"type": "uri_folder" |
| 133 |
} |
| 134 |
}, |
| 135 |
"resources": { |
| 136 |
"instance_count": 1 |
| 137 |
}, |
| 138 |
"type": "command", |
| 139 |
"version": "2" |
| 140 |
} |
| 141 |
] |
| 142 |
''' |
| 143 |
|
| 144 |
|
| 145 |
try: |
| 146 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ml import MLClientCommon |
| 147 |
from azure.core.exceptions import ResourceNotFoundError |
| 148 |
except ImportError: |
| 149 |
|
| 150 |
pass |
| 151 |
|
| 152 |
|
| 153 |
class AzureRMMLComponentInfo(MLClientCommon): |
| 154 |
def __init__(self): |
| 155 |
|
| 156 |
self.module_arg_spec = dict( |
| 157 |
name=dict( |
| 158 |
type='str', |
| 159 |
required=False, |
| 160 |
), |
| 161 |
resource_group=dict( |
| 162 |
type='str', |
| 163 |
required=True, |
| 164 |
), |
| 165 |
ml_workspace=dict( |
| 166 |
type='str', |
| 167 |
required=True, |
| 168 |
), |
| 169 |
ml_registry=dict( |
| 170 |
type='str', |
| 171 |
), |
| 172 |
version=dict( |
| 173 |
type='str', |
| 174 |
), |
| 175 |
label=dict( |
| 176 |
type='str', |
| 177 |
), |
| 178 |
list_type=dict( |
| 179 |
type='str', |
| 180 |
choices=['archived', 'active', 'all'], |
| 181 |
), |
| 182 |
) |
| 183 |
|
| 184 |
self._client = None |
| 185 |
|
| 186 |
self.results = dict( |
| 187 |
ml_components=[] |
| 188 |
) |
| 189 |
|
| 190 |
required_one_of = [('ml_workspace', 'ml_registry')] |
| 191 |
mutually_exclusive = [('version', 'label'), |
| 192 |
('ml_workspace', 'ml_registry'), |
| 193 |
('name', 'list_type')] |
| 194 |
required_together = [('ml_workspace', 'resource_group')] |
| 195 |
|
| 196 |
super(AzureRMMLComponentInfo, self).__init__(self.module_arg_spec, |
| 197 |
supports_tags=False, |
| 198 |
supports_check_mode=True, |
| 199 |
facts_module=True, |
| 200 |
required_one_of=required_one_of, |
| 201 |
mutually_exclusive=mutually_exclusive, |
| 202 |
required_together=required_together |
| 203 |
) |
| 204 |
|
| 205 |
def exec_module(self, **kwargs): |
| 206 |
|
| 207 |
for key in list(self.module_arg_spec.keys()): |
| 208 |
setattr(self, key, kwargs[key]) |
| 209 |
|
| 210 |
if self.name: |
| 211 |
try: |
| 212 |
result = self.client.components.get(name=self.name, |
| 213 |
version=self.version, |
| 214 |
label=self.label) |
| 215 |
ml_components = [self.entity_to_dict(result)] |
| 216 |
except ResourceNotFoundError: |
| 217 |
ml_components = [] |
| 218 |
else: |
| 219 |
list_view_type = self.get_list_view_type(self.list_type) |
| 220 |
results = self.client.components.list(name=self.name, |
| 221 |
list_view_type=list_view_type) |
| 222 |
ml_components = [self.entity_to_dict(self.client.components.get(x.name, version=x.latest_version)) for x in results] |
| 223 |
|
| 224 |
self.results['ml_components'] = ml_components |
| 225 |
return self.results |
| 226 |
|
| 227 |
|
| 228 |
def main(): |
| 229 |
AzureRMMLComponentInfo() |
| 230 |
|
| 231 |
|
| 232 |
if __name__ == '__main__': |
| 233 |
main() |