Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_batchaccountpool.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2024 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10 DOCUMENTATION = '''
11 ---
12 module: azure_rm_batchaccountpool
13 version_added: "3.0.0"
14 short_description: Manages a Batch Account Pool on Azure
15 description:
16 - Create, update and delete instance of Azure Batch Account Pool.
17
18 options:
19 resource_group:
20 description:
21 - The name of the resource group in which to create the Batch Account Pool.
22 required: true
23 type: str
24 batch_account_name:
25 description:
26 - The name of the Batch Account.
27 required: true
28 type: str
29 name:
30 description:
31 - The name of the Batch Account Pool.
32 required: true
33 type: str
34 display_name:
35 description:
36 - The display name for the pool.
37 type: str
38 identity:
39 description:
40 - The type of identity used for the Batch Pool.
41 - If the pool identity is updated during update an existing pool.
42 - Only the new vms which are created after the pool shrinks to 0 will have the updated identities.
43 type: dict
44 suboptions:
45 type:
46 description:
47 - The type of identity used for the Batch Pool.
48 required: true
49 type: str
50 choices:
51 - None
52 - UserAssigned
53 user_assigned_identities:
54 description:
55 - The list of user identities associated with the Batch pool.
56 - The key is the identity's ID and value contains 'principal_id' and 'client_id'.
57 type: dict
58 vm_size:
59 description:
60 - For information about available sizes of virtual machines for Cloud Services Pools.
61 - Batch supports all Cloud Services VM sizes except ExtraSmall, A1V2 and A2V2,
62 - Batch supports all Azure VM sizes except STANDARD_A0 and those with premium storage (STANDARD_GS, STANDARD_DS, and STANDARD_DSV2 series).
63 type: str
64 deployment_configuration:
65 description:
66 - Using CloudServiceConfiguration specifies that the nodes should be creating using Azure Cloud Services (PaaS).
67 - Using VirtualMachineConfiguration uses Azure Virtual Machines (IaaS).
68 type: dict
69 suboptions:
70 cloud_service_configuration:
71 description:
72 - This property and virtualMachineConfiguration are mutually exclusive and one of the properties must be specified.
73 - This property cannot be specified if the Batch account was created with its poolAllocationMode property set to 'UserSubscription'.
74 type: dict
75 suboptions:
76 os_family:
77 description:
78 - I(os_family=2) equivalent to Windows Server 2008 R2 SP1.
79 - I(os_family=3) equivalent to Windows Server 2012.
80 - I(os_family=4) equivalent to Windows Server 2012 R2.
81 - I(os_family=5) equivalent to Windows Server 2016.
82 - I(os_family=6) equivalent to Windows Server 2019.
83 type: str
84 default: '*'
85 os_version:
86 description:
87 - The default value is C(*) which specifies the latest operating system version for the specified OS family.
88 type: str
89 virtual_machine_configuration:
90 description:
91 - This property and cloudServiceConfiguration are mutually exclusive and one of the properties must be specified.
92 type: dict
93 suboptions:
94 image_reference:
95 description:
96 - A reference to an Azure Virtual Machines Marketplace image or the zure Image resource of a custom Virtual Machine.
97 - To get the list of all imageReferences verified by Azure Batch, see the 'List supported node agent SKUs' operation.
98 type: dict
99 required: true
100 suboptions:
101 publisher:
102 description:
103 - For example, C(Canonical) or C(MicrosoftWindowsServer).
104 type: str
105 offer:
106 description:
107 - For example, C(UbuntuServer) or C(WindowsServer).
108 type: str
109 sku:
110 description:
111 - For example, C(18.04-LTS) or C(2022-datacenter).
112 type: str
113 version:
114 description:
115 - A value of 'latest' can be specified to select the latest version of an image.
116 - If omitted, the default is C(latest).
117 type: str
118 id:
119 description:
120 - This property is mutually exclusive with other properties.
121 - The Azure Compute Gallery Image must have replicas in the same region as the Azure Batch account.
122 - Sample as C('/subscriptions/{sub_Id}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/images/{imageName}).
123 type: str
124 node_agent_sku_id:
125 description:
126 - The Batch node agent is a program that runs on each node in the pool.
127 - Provides the command-and-control interface between the node and the Batch service.
128 - There are different implementations of the node agent, known as SKUs, for different operating systems.
129 - You must specify a node agent SKU which matches the selected image reference.
130 - To get the list of supported node agent SKUs along with their list of verified image references.
131 type: str
132 required: true
133 windows_configuration:
134 description:
135 - This property must not be specified if the imageReference specifies a Linux OS image.
136 type: dict
137 suboptions:
138 enable_automatic_updates:
139 description:
140 - If omitted, the default value is C(true).
141 type: bool
142 default: true
143 data_disks:
144 description:
145 - This property must be specified if the compute nodes in the pool need to have empty data disks attached to them.
146 type: list
147 elements: dict
148 suboptions:
149 lun:
150 description:
151 - The lun is used to uniquely identify each data disk.
152 - If attaching multiple disks, each should have a distinct lun.
153 - The value must be between 0 and 63, inclusive.
154 required: true
155 type: int
156 caching:
157 description:
158 - The caching mode for the disk
159 type: str
160 choices:
161 - None
162 - ReadOnly
163 - ReadWrite
164 disk_size_gb:
165 description:
166 - The initial disk size in GB when creating new data disk.
167 type: int
168 required: true
169 storage_account_type:
170 description:
171 - The data disk type.
172 - C(Standard_LRS) for the data disk should use standard locally redundant storage.
173 - C(Premium_LRS) for the he data disk should use premium locally redundant storage.
174 type: str
175 default: Standard_LRS
176 choices:
177 - Standard_LRS
178 - Premium_LRS
179 - StandardSSD_LRS
180 license_type:
181 description:
182 - This only applies to images that contain the Windows operating system.
183 - Should only be used when you hold valid on-premises licenses for the nodes which will be deployed.
184 - C(Windows_Server), The on-premises license is for Windows Server.
185 - C(Windows_Client), The on-premises license is for Windows Client.
186 type: str
187 container_configuration:
188 description:
189 - If specified, setup is performed on each node in the pool to allow tasks to run in containers.
190 - All regular tasks and job manager tasks run on this pool must specify the containerSettings property.
191 - All other tasks may specify it.
192 type: dict
193 suboptions:
194 type:
195 description:
196 - The container technology to be used.
197 required: true
198 type: str
199 choices:
200 - DockerCompatible
201 - CriCompatible
202 container_image_names:
203 description:
204 - This is the full image reference, as would be specified to "docker pull".
205 - "An image will be sourced from the default Docker registry
206 unless the image is fully qualified with an alternative registry."
207 type: list
208 elements: str
209 container_registries:
210 description:
211 - "If any images must be downloaded from a private registry which requires credentials,
212 then those credentials must be provided here."
213 type: list
214 elements: dict
215 suboptions:
216 user_name:
217 description:
218 - The user name to log into the registry server.
219 type: str
220 password:
221 description:
222 - The password to log into the registry server.
223 type: str
224 registry_server:
225 description:
226 - If omitted, the default is C(docker.io).
227 type: str
228 default: 'docker.io'
229 identity_reference:
230 description:
231 - The reference to a user assigned identity associated with the Batch pool which a compute node will use.
232 type: dict
233 suboptions:
234 resource_id:
235 description:
236 - The ARM resource id of the user assigned identity.
237 type: str
238 disk_encryption_configuration:
239 description:
240 - If specified, encryption is performed on each node in the pool during node provisioning.
241 type: dict
242 suboptions:
243 targets:
244 description:
245 - On Linux pool, only C(TemporaryDisk) is supported.
246 - on Windows pool, C(OsDisk) and C(TemporaryDisk) must be specified.
247 type: list
248 elements: str
249 choices:
250 - TemporaryDisk
251 - OsDisk
252 node_placement_configuration:
253 description:
254 - This configuration will specify rules on how nodes in the pool during node provisioning.
255 type: dict
256 suboptions:
257 policy:
258 description:
259 - Allocation policy used by Batch Service to provision the nodes.
260 - If not specified, Batch will use the regional policy.
261 type: str
262 choices:
263 - Regional
264 - Zonal
265 extensions:
266 description:
267 - If specified, the extensions mentioned in this configuration will be installed on each node.
268 type: list
269 elements: dict
270 suboptions:
271 name:
272 description:
273 - The name of the virtual machine extension.
274 required: true
275 type: str
276 publisher:
277 description:
278 - The name of the extension handler publisher.
279 required: true
280 type: str
281 type:
282 description:
283 - The type of the extensions.
284 type: str
285 required: true
286 type_handler_version:
287 description:
288 - The version of script handler.
289 type: str
290 auto_upgrade_minor_version:
291 description:
292 - Indicates whether the extension should use a newer minor version if one is available at deployment time.
293 - Once deployed, the extension will not upgrade minor versions unless redeployed, even with this property set to true.
294 type: bool
295 enable_automatic_upgrade:
296 description:
297 - "Indicates whether the extension should be automatically upgraded by the platform
298 if there is a newer version of the extension available."
299 type: bool
300 settings:
301 description:
302 - JSON formatted public settings for the extension.
303 type: json
304 protected_settings:
305 description:
306 - The extension can contain either protectedSettings or protectedSettingsFromKeyVault or no protected settings at all.
307 type: json
308 provision_after_extensions:
309 description:
310 - Collection of extension names after which this extension needs to be provisioned.
311 type: list
312 elements: str
313 os_disk:
314 description:
315 - Contains configuration for ephemeral OSDisk settings.
316 type: dict
317 suboptions:
318 ephemeral_os_disk_settings:
319 description:
320 - Specifies the ephemeral Disk Settings for the operating system disk used by the virtual machine.
321 type: dict
322 suboptions:
323 placement:
324 description:
325 - This property can be used by user in the request to choose which location the operating system should be in.
326 type: str
327 caching:
328 description:
329 - The type of caching to enable for the disk.
330 type: str
331 choices:
332 - None
333 - ReadOnly
334 - ReadWrite
335 managed_disk:
336 description:
337 - The data disk config.
338 type: dict
339 suboptions:
340 storage_account_type:
341 description:
342 - The storage account type for use in creating data disks or OSdisk.
343 type: str
344 choices:
345 - Standard_LRS
346 - Premium_LRS
347 - StandardSSD_LRS
348 disk_size_gb:
349 description:
350 - The initial disk size in GB when creating new OS disk.
351 type: int
352 write_accelerator_enabled:
353 description:
354 - Specifies whether writeAccelerator should be enabled or disabled on the disk.
355 type: bool
356 security_profile:
357 description:
358 - Specifies the security profile settings for the virtual machine or virtual machine scale set.
359 type: dict
360 suboptions:
361 security_type:
362 description:
363 - Specifies the SecurityType of the virtual machine.
364 - It has to be set to any specified value to enable UefiSettings.
365 type: str
366 default: trustedLaunch
367 encryption_at_host:
368 description:
369 - "This property can be used by user in the request to enable or disable the Host Encryption
370 for the virtual machine or virtual machine scale set."
371 - This willenable the encryption for all the disks including Resource/Temp disk at host itself.
372 type: bool
373 uefi_settings:
374 description:
375 - Specifies the security settings like secure boot and vTPM used while creating the virtual machine.
376 type: dict
377 suboptions:
378 secure_boot_enabled:
379 description:
380 - Specifies whether secure boot should be enabled on the virtual machine.
381 type: bool
382 v_tpm_enabled:
383 description:
384 - Specifies whether vTPM should be enabled on the virtual machine.
385 type: bool
386 service_artifact_reference:
387 description:
388 - The service artifact reference ID.
389 - "Such as C(/subscriptions/{subId}/resourceGroups/{testRG}/providers/Microsoft.Compute/galleries
390 /{gName}/serviceArtifacts/{ArtName}/vmArtifactsProfiles/{ProfilesName})."
391 type: dict
392 suboptions:
393 id:
394 description:
395 - The service artifact reference ID of the vmArtifactsProfiles.
396 type: str
397 scale_settings:
398 description:
399 - Defines the desired size of the pool.
400 - "This can either be 'fixedScale' where the requested targetDedicatedNodes is specified,
401 or 'autoScale' which defines a formula which is periodically reevaluated."
402 - If this property is not specified, the pool will have a fixed scale with 0 targetDedicatedNodes.
403 type: dict
404 suboptions:
405 fixed_scale:
406 description:
407 - This property and autoScale are mutually exclusive and one of the properties must be specified.
408 type: dict
409 suboptions:
410 resize_timeout:
411 description:
412 - The default value is 15 minutes C(P15M).
413 - Timeout values use ISO 8601 format. For example, use PT10M for 10 minutes.
414 - The minimum value is 5 minutes.
415 - If you specify a value less than 5 minutes, the Batch service rejects the request with an error.
416 type: str
417 default: P15M
418 target_dedicated_nodes:
419 description:
420 - At least one of targetDedicatedNodes, targetLowPriorityNodes must be set.
421 type: int
422 target_low_priority_nodes:
423 description:
424 - At least one of targetDedicatedNodes, targetLowPriorityNodes must be set.
425 type: int
426 node_deallocation_option:
427 description:
428 - If omitted, the default value is C(Requeue).
429 type: str
430 choices:
431 - Requeue
432 - Terminate
433 - TaskCompletion
434 - RetainedData
435 auto_scale:
436 description:
437 - This property and fixedScale are mutually exclusive and one of the properties must be specified. must be specified.
438 type: dict
439 suboptions:
440 formula:
441 description:
442 - A formula for the desired number of compute nodes in the pool.
443 type: str
444 required: true
445 evaluation_interval:
446 description:
447 - If omitted, the default value is 15 minutes (PT15M).
448 type: str
449 default: P15M
450 inter_node_communication:
451 description:
452 - This imposes restrictions on which nodes can be assigned to the pool.
453 - Enabling this value can reduce the chance of the requested number of nodes to be allocated in the pool.
454 - If not specified, this value defaults to C(Disabled).
455 type: str
456 choices:
457 - Enabled
458 - Disabled
459 network_configuration:
460 description:
461 - The network configuration for a pool.
462 type: dict
463 suboptions:
464 subnet_id:
465 description:
466 - The virtual network must be in the same region and subscription as the Azure Batch account.
467 - The specified subnet should have enough free IP addresses to accommodate the number of nodes in the pool.
468 - If the subnet doesn't have enough free IP addresses, the pool will partially allocate compute nodes and a resize error will occur.
469 type: str
470 dynamic_vnet_assignment_scope:
471 description:
472 - The scope of dynamic vnet assignment.
473 type: str
474 choices:
475 - none
476 - job
477 endpoint_configuration:
478 description:
479 - Pool endpoint configuration is only supported on pools with the virtualMachineConfiguration property.
480 type: dict
481 suboptions:
482 inbound_nat_pools:
483 description:
484 - The maximum number of inbound NAT pools per Batch pool is 5.
485 - If the maximum number of inbound NAT pools is exceeded the request fails with HTTP status code 400.
486 type: list
487 elements: dict
488 suboptions:
489 name:
490 description:
491 - The name must be unique within a Batch pool.
492 - The name contain letters, numbers, underscores, periods, and hyphens.
493 type: str
494 required: true
495 protocol:
496 description:
497 - The protocol of the endpoint.
498 type: str
499 required: true
500 choices:
501 - UDP
502 - TCP
503 backend_port:
504 description:
505 - This must be unique within a Batch pool.
506 - Acceptable values are between 1 amd 65535 except for 22.
507 type: int
508 required: true
509 frontend_port_range_start:
510 description:
511 - Acceptable values range between 1 and 65534 except ports overlap
512 - If any reserved or overlapping values are provided the request fails with HTTP status code 400.
513 type: int
514 required: true
515 frontend_port_range_end:
516 description:
517 - Acceptable values range between 1 and 65534 except ports from 50000 to 55000 which are reserved by the Batch service.
518 - All ranges within a pool must be distinct and cannot overlap.
519 type: int
520 required: true
521 network_security_group_rules:
522 description:
523 - The maximum number of rules that can be specified across all the endpoints on a Batch pool is 25.
524 - If no network security group rules are specified.
525 - default rule will be created to allow inbound access to the specified backendPort.
526 type: list
527 elements: dict
528 suboptions:
529 priority:
530 description:
531 - Priorities within a pool must be unique and are evaluated in order of priority
532 type: int
533 required: true
534 access:
535 description:
536 - The action that should be taken for a specified IP address, subnet range or tags.
537 type: str
538 choices:
539 - Allow
540 - Deny
541 required: true
542 source_address_prefix:
543 description:
544 - Valid values are a single IP address (i.e. 10.10.10.10).
545 - Valid values are a single IP address.
546 type: str
547 source_port_ranges:
548 description:
549 - Valid values are '*' (for all ports 0 - 65535) or arrays of orts or port ranges (i.e. 100-200).
550 type: list
551 elements: str
552 public_ip_address_configuration:
553 description:
554 - This property is only supported on Pools with the virtualMachineConfiguration property.
555 type: dict
556 suboptions:
557 provision:
558 description:
559 - The public IP Address configuration's provision.
560 type: str
561 default: BatchManaged
562 choices:
563 - BatchManaged
564 - UserManaged
565 - NoPublicIPAddresses
566 ip_address_ids:
567 description:
568 - "The number of IPs specified here limits the maximum size of the Pool
569 100 dedicated nodes or 100 Spot/low-priority nodes can be allocated for each public IP."
570 type: list
571 elements: str
572 enable_accelerated_networking:
573 description:
574 - Accelerated networking enables single root I/O virtualization (SR-IOV) to a VM.
575 - Which may lead to improved networking performance.
576 type: bool
577 task_slots_per_node:
578 description:
579 - The default value is C(1).
580 - The maximum value is the smaller of 4 times the number of cores of the vmSize of the pool or 256.
581 type: int
582 default: 1
583 task_scheduling_policy:
584 description:
585 - Specifies how tasks should be distributed across compute nodes.
586 type: dict
587 suboptions:
588 node_fill_type:
589 description:
590 - How tasks should be distributed across compute nodes.
591 type: str
592 choices:
593 - Spread
594 - Pack
595 user_accounts:
596 description:
597 - The list of user accounts to be created on each node in the pool.
598 type: list
599 elements: dict
600 suboptions:
601 name:
602 description:
603 - The name of the user account. Names can contain any Unicode characters up to a maximum length of 20.
604 type: str
605 required: true
606 password:
607 description:
608 - The password for the user account.
609 type: str
610 required: true
611 elevation_level:
612 description:
613 - C(NonAdmin) - the auto user is a standard user without elevated access.
614 - C(Admin) - The auto user is a user with elevated access and operates with full Administrator permissions.
615 type: str
616 default: NonAdmin
617 choices:
618 - NonAdmin
619 - Admin
620 linux_user_configuration:
621 description:
622 - Properties used to create a user account on a Linux node.
623 type: dict
624 suboptions:
625 uid:
626 description:
627 - The uid and gid properties must be specified together or not at all.
628 - If not specified the underlying operating system picks the uid.
629 type: int
630 gid:
631 description:
632 - The uid and gid properties must be specified together or not at all.
633 - If not specified the underlying operating system picks the gid.
634 type: int
635 ssh_private_key:
636 description:
637 - The private key must not be password protected.
638 - "The private key is used to automatically configure asymmetric-key based authentication for SSH between nodes in a Linux pool
639 when the pool's enableInterNodeCommunication property is true."
640 - It does this by placing the key pair into the user's .ssh directory.
641 - If not specified, password-less SSH is not configured between nodes (no modification of the user's .ssh directory is done).
642 type: str
643 windows_user_configuration:
644 description:
645 - Properties used to create a user account on a Windows node.
646 type: dict
647 suboptions:
648 login_mode:
649 description:
650 - Specifies login mode for the user.
651 - The default value for VirtualMachineConfiguration pools is interactive mode and for CloudServiceConfiguration pools is batch mode.
652 type: str
653 choices:
654 - Batch
655 - Interactive
656 metadata:
657 description:
658 - The Batch service does not assign any meaning to this metadata; it is solely for the use of user code.
659 type: list
660 elements: dict
661 suboptions:
662 name:
663 description:
664 - The name of the metadata item.
665 type: str
666 required: true
667 value:
668 description:
669 - The value of the metadata item.
670 type: str
671 required: true
672 start_task:
673 description:
674 - In an PATCH (update) operation, this property can be set to an empty object to remove the start task from the pool.
675 type: dict
676 suboptions:
677 command_line:
678 description:
679 - The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion.
680 - If you want to take advantage of such features, you should invoke the shell in the command line.
681 - Required if any other properties of the startTask are specified.
682 type: str
683 resource_files:
684 description:
685 - A list of files that the Batch service will download to the compute node before running the command line.
686 - A single file or multiple files to be downloaded to a compute node.
687 type: list
688 elements: dict
689 suboptions:
690 auto_storage_container_name:
691 description:
692 - The autoStorageContainerName, storageContainerUrl and httpUrl properties are mutually exclusive and one of them must be specified.
693 type: str
694 storage_container_url:
695 description:
696 - The autoStorageContainerName, storageContainerUrl and httpUrl properties are mutually exclusive and one of them must be specified.
697 - This URL must be readable and listable from compute nodes.
698 - There are three ways to get such a URL for a container in Azure storage.
699 - "Include a Shared Access Signature (SAS) granting read and list permissions on the container,
700 use a managed identity with read and list permissions, or set the ACL for the container to allow public access."
701 type: str
702 http_url:
703 description:
704 - The autoStorageContainerName, storageContainerUrl and httpUrl properties are mutually exclusive and one of them must be specified.
705 - If the URL points to Azure Blob Storage, it must be readable from compute nodes.
706 - There are three ways to get such a URL for a blob in Azure storage.
707 - "Include a Shared Access Signature (SAS) granting read permissions on the blob, use a managed identity with read permission,
708 or set the ACL for the blob or its container to allow public access."
709 type: str
710 blob_prefix:
711 description:
712 - The property is valid only when autoStorageContainerName or storageContainerUrl is used.
713 - This prefix can be a partial filename or a subdirectory.
714 - If a prefix is not specified, all the files in the container will be downloaded.
715 type: str
716 file_path:
717 description:
718 - If the httpUrl property is specified, the filePath is required and
719 describes the path which the file will be downloaded to, including the filename.
720 - If the autoStorageContainerName or storageContainerUrl property is specified, filePath is optional and
721 is the directory to download the files to.
722 - "In the case where filePath is used as a directory, any directory structure already associated with the input data
723 will be retained in full and appended to the specified filePath directory."
724 - The specified relative path cannot break out of the task's working directory.
725 type: str
726 file_mode:
727 description:
728 - This property applies only to files being downloaded to Linux compute nodes.
729 - It will be ignored if it is specified for a resourceFile which will be downloaded to a Windows node.
730 - If this property is not specified for a Linux node, then a default value of 0770 is applied to the file.
731 type: str
732 identity_reference:
733 description:
734 - The reference to a user assigned identity associated with the Batch pool which a compute node will use.
735 type: dict
736 suboptions:
737 resource_id:
738 description:
739 - The ARM resource id of the user assigned identity.
740 type: str
741 environment_settings:
742 description:
743 - A list of environment variable settings for the start task.
744 type: list
745 elements: dict
746 suboptions:
747 name:
748 description:
749 - The name of the environment variable.
750 type: str
751 required: true
752 value:
753 description:
754 - The value of the environment variable.
755 type: str
756 user_identity:
757 description:
758 - If omitted, the task runs as a non-administrative user unique to the task.
759 type: dict
760 suboptions:
761 user_name:
762 description:
763 - The username of the task user identity.
764 - The userName and autoUser properties are mutually exclusive; you must specify one but not both.
765 type: str
766 auto_user:
767 description:
768 - The autouser config of the task user identity.
769 - The userName and autoUser properties are mutually exclusive; you must specify one but not both.
770 type: dict
771 suboptions:
772 scope:
773 description:
774 - The scope of the auto user scope.
775 - The default value is Pool.
776 - If the pool is running Windows a value of Task should be specified if stricter isolation between tasks is required.
777 type: str
778 default: Pool
779 choices:
780 - Task
781 - Pool
782 elevation_level:
783 description:
784 - The auto user elevation level.
785 type: str
786 default: NonAdmin
787 choices:
788 - NonAdmin
789 - Admin
790 max_task_retry_count:
791 description:
792 - The Batch service retries a task if its exit code is nonzero.
793 - Note that this value specifically controls the number of retries.
794 - The Batch service will try the task once, and may then retry up to this limit.
795 type: int
796 default: 0
797 wait_for_success:
798 description:
799 - If true and the start task fails on a compute node.
800 - The Batch service retries the start task up to its maximum retry count (maxTaskRetryCount).
801 - "If the task has still not completed successfully after all retries, then the Batch service marks the compute node unusable,
802 and will not schedule tasks to it."
803 - This condition can be detected via the node state and scheduling error detail.
804 - If false, the Batch service will not wait for the start task to complet.
805 type: bool
806 container_settings:
807 description:
808 - "When this is specified, all directories recursively below the AZ_BATCH_NODE_ROOT_DIR are mapped into the container,
809 all task environment variables are mapped into the container, and the task command line is executed in the container."
810 type: dict
811 suboptions:
812 container_run_options:
813 description:
814 - "These additional options are supplied as arguments to the 'docker create' command,
815 in addition to those controlled by the Batch Service."
816 type: str
817 image_name:
818 description:
819 - This is the full image reference, as would be specified to "docker pull".
820 - If no tag is provided as part of the image name, the tag ":latest" is used as a default.
821 type: str
822 registry:
823 description:
824 - This setting can be omitted if was already provided at pool creation.
825 type: dict
826 suboptions:
827 user_name:
828 description:
829 - he user name to log into the registry server.
830 type: str
831 password:
832 description:
833 - The password to log into the registry server.
834 type: str
835 registry_server:
836 description:
837 - If omitted, the default is "docker.io".
838 type: str
839 default: 'docker.io'
840 identity_reference:
841 description:
842 - The reference to a user assigned identity associated with the Batch pool which a compute node will use.
843 type: dict
844 suboptions:
845 resource_id:
846 description:
847 - The ARM resource id of the user assigned identity.
848 type: str
849 working_directory:
850 description:
851 - A flag to indicate where the container task working directory is.
852 type: str
853 choices:
854 - TaskWorkingDirectory
855 - ContainerImageDefault
856 application_packages:
857 description:
858 - Changes to application package references affect all new compute nodes joining the pool.
859 - But do not affect compute nodes that are already in the pool until they are rebooted or reimaged.
860 - There is a maximum of 10 application package references on any given pool.
861 type: list
862 elements: dict
863 suboptions:
864 id:
865 description:
866 - The ID of the application package to install.
867 - This must be inside the same batch account as the pool.
868 - This can either be a reference to a specific version or the default version if one exists.
869 type: str
870 required: true
871 version:
872 description:
873 - "If this is omitted, and no default version is specified for this application,
874 the request fails with the error code InvalidApplicationPackageReferences."
875 - If you are calling the REST API directly, the HTTP status code is 409.
876 type: str
877 certificates:
878 description:
879 - For Windows compute nodes, the Batch service installs the certificates to the specified certificate store and location.
880 - "For Linux compute nodes, the certificates are stored in a directory inside the task working directory and
881 an environment variable AZ_BATCH_CERTIFICATES_DIR is supplied to the task to query for this location."
882 - "For certificates with visibility of 'remoteUser', a 'certs' directory is created in the user's home directory and
883 certificates are placed in that directory."
884 type: list
885 elements: dict
886 suboptions:
887 id:
888 description:
889 - The fully qualified ID of the certificate to install on the pool.
890 - This must be inside the same batch account as the pool.
891 type: str
892 required: true
893 store_location:
894 description:
895 - The default value is C(CurrentUser).
896 - This property is applicable only for pools configured with Windows nodes.
897 - "For Linux compute nodes, the certificates are stored in a directory inside the task working directory and
898 an environment variable AZ_BATCH_CERTIFICATES_DIR is supplied to the task to query for this location."
899 - "For certificates with visibility of 'remoteUser', a 'certs' directory is created in the user's home directory
900 and certificates are placed in that directory."
901 type: str
902 default: CurrentUser
903 choices:
904 - CurrentUser
905 - LocalMachine
906 store_name:
907 description:
908 - This property is applicable only for pools configured with Windows nodes.
909 - This created with cloudServiceConfiguration, or with virtualMachineConfiguration using a Windows image reference.
910 type: str
911 default: My
912 choices:
913 - My
914 - Root
915 - CA
916 - Trust
917 - Disallowed
918 - TrustedPeople
919 - TrustedPublisher
920 - AuthRoot
921 - AddressBook
922 visibility:
923 description:
924 - Which user accounts on the compute node should have access to the private data of the certificate.
925 type: list
926 elements: str
927 choices:
928 - StartTask
929 - Task
930 - RemoteUser
931 application_licenses:
932 description:
933 - The list of application licenses must be a subset of available Batch service application licenses.
934 - If a license is requested which is not supported, pool creation will fail.
935 type: list
936 elements: str
937 mount_configuration:
938 description:
939 - This supports Azure Files, NFS, CIFS/SMB, and Blobfuse.
940 type: list
941 elements: dict
942 suboptions:
943 azure_blob_file_system_configuration:
944 description:
945 - Configuration of the azure blob file system.
946 - This property is mutually exclusive with all other properties.
947 type: dict
948 suboptions:
949 account_name:
950 description:
951 - The Azure Storage Account name.
952 type: str
953 required: true
954 container_name:
955 description:
956 - The Azure Blob Storage Container name.
957 type: str
958 required: true
959 account_key:
960 description:
961 - This property is mutually exclusive with both sasKey and identity; exactly one must be specified.
962 type: str
963 sas_key:
964 description:
965 - This property is mutually exclusive with both accountKey and identity; exactly one must be specified.
966 type: str
967 blobfuse_options:
968 description:
969 - These are C(net use) options in Windows and C(mount) options in Linux.
970 type: str
971 choices:
972 - 'net use'
973 - mount
974 relative_mount_path:
975 description:
976 - "All file systems are mounted relative to the Batch mounts directory,
977 accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable."
978 type: str
979 required: true
980 identity_reference:
981 description:
982 - This property is mutually exclusive with both accountKey and sasKey; exactly one must be specified.
983 type: dict
984 suboptions:
985 resource_id:
986 description:
987 - The ARM resource id of the user assigned identity.
988 type: str
989 nfs_mount_configuration:
990 description:
991 - Configuration of the nfs mount.
992 - This property is mutually exclusive with all other properties.
993 type: dict
994 suboptions:
995 source:
996 description:
997 - The URI of the file system to mount.
998 type: str
999 required: true
1000 relative_mount_path:
1001 description:
1002 - "All file systems are mounted relative to the Batch mounts directory,
1003 accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable."
1004 type: str
1005 required: true
1006 mount_options:
1007 description:
1008 - These are C(net use) options in Windows and C(mount) options in Linux.
1009 type: str
1010 choices:
1011 - 'net use'
1012 - mount
1013 cifs_mount_configuration:
1014 description:
1015 - Configuration of the cifs mount.
1016 - This property is mutually exclusive with all other properties.
1017 type: dict
1018 suboptions:
1019 user_name:
1020 description:
1021 - The user to use for authentication against the CIFS file system.
1022 type: str
1023 required: true
1024 source:
1025 description:
1026 - The URI of the file system to mount.
1027 type: str
1028 required: true
1029 relative_mount_path:
1030 description:
1031 - "All file systems are mounted relative to the Batch mounts directory,
1032 accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable."
1033 type: str
1034 required: true
1035 mount_options:
1036 description:
1037 - These are C(net use) options in Windows and C(mount) options in Linux.
1038 type: str
1039 choices:
1040 - 'net use'
1041 - mount
1042 password:
1043 description:
1044 - The password to use for authentication against the CIFS file system.
1045 type: str
1046 required: true
1047 azure_file_share_configuration:
1048 description:
1049 - Configuration of the azure file share.
1050 - This property is mutually exclusive with all other properties.
1051 type: dict
1052 suboptions:
1053 account_name:
1054 description:
1055 - The Azure Storage account name.
1056 type: str
1057 required: true
1058 azure_file_url:
1059 description:
1060 - This is of the form 'https://{account}.file.core.windows.net/'.
1061 type: str
1062 required: true
1063 account_key:
1064 description:
1065 - The Azure Storage account key.
1066 type: str
1067 required: true
1068 relative_mount_path:
1069 description:
1070 - "All file systems are mounted relative to the Batch mounts directory,
1071 accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable."
1072 type: str
1073 required: true
1074 mount_options:
1075 description:
1076 - These are C(net use) options in Windows and C(mount) options in Linux.
1077 type: str
1078 choices:
1079 - 'net use'
1080 - mount
1081 target_node_communication_mode:
1082 description:
1083 - If omitted, the default value is C(Default).
1084 type: str
1085 default: Default
1086 choices:
1087 - Default
1088 - Classic
1089 - Simplified
1090 upgrade_policy:
1091 description:
1092 - Describes an upgrade policy.
1093 type: dict
1094 suboptions:
1095 mode:
1096 description:
1097 - Specifies the mode of an upgrade to virtual machines in the scale set.
1098 type: str
1099 choices:
1100 - automatic
1101 - manual
1102 - rolling
1103 required: true
1104 automatic_os_upgrade_policy:
1105 description:
1106 - The configuration parameters used for performing automatic OS upgrade.
1107 type: dict
1108 suboptions:
1109 disable_automatic_rollback:
1110 description:
1111 - Whether OS image rollback feature should be disabled.
1112 type: bool
1113 enable_automatic_os_upgrade:
1114 description:
1115 - "Indicates whether OS upgrades should automatically be applied to scale set instances in a rolling fashion
1116 when a newer version of the OS image becomes available."
1117 type: bool
1118 use_rolling_upgrade_policy:
1119 description:
1120 - Indicates whether rolling upgrade policy should be used during Auto OS Upgrade.
1121 - Auto OS Upgrade will fallback to the default policy if no policy is defined on the VMSS.
1122 type: bool
1123 os_rolling_upgrade_deferral:
1124 description:
1125 - Defer OS upgrades on the TVMs if they are running tasks.
1126 type: bool
1127 rolling_upgrade_policy:
1128 description:
1129 - This property is only supported on Pools with the virtualMachineConfiguration property.
1130 type: dict
1131 suboptions:
1132 enable_cross_zone_upgrade:
1133 description:
1134 - Allow VMSS to ignore AZ boundaries when constructing upgrade batches.
1135 - Take into consideration the Update Domain and maxBatchInstancePercent to determine the batch size.
1136 - If this field is not set, Azure Azure Batch will not set its default value.
1137 - "The value of enableCrossZoneUpgrade on the created VirtualMachineScaleSet
1138 will be decided by the default configurations on VirtualMachineScaleSet."
1139 - This field is able to be set to true or false only when using NodePlacementConfiguration as Zonal.
1140 type: bool
1141 max_batch_instance_percent:
1142 description:
1143 - The maximum percent of total virtual machine instances that will be upgraded simultaneously by the rolling upgrade in one batch.
1144 - "As this is a maximum, unhealthy instances in previous or future batches can cause the percentage of instances
1145 in a batch to decrease to ensure higher reliability."
1146 - The value of this field should be between 5 and 100, inclusive.
1147 - "If both maxBatchInstancePercent and maxUnhealthyInstancePercent are assigned with value,
1148 the value of maxBatchInstancePercent should not be more than maxUnhealthyInstancePercent."
1149 type: int
1150 max_unhealthy_instance_percent:
1151 description:
1152 - "The maximum percentage of the total virtual machine instances in the scale set that can be simultaneously unhealthy,
1153 either as a result of being upgraded, or by being found in an unhealthy state by the virtual machine health checks
1154 before the rolling upgrade aborts."
1155 - This constraint will be checked prior to starting any batch.
1156 - "If both maxBatchInstancePercent and maxUnhealthyInstancePercent are assigned with value,
1157 the value of maxBatchInstancePercent should not be more than maxUnhealthyInstancePercent."
1158 type: int
1159 max_unhealthy_upgraded_instance_percent:
1160 description:
1161 - The maximum percentage of upgraded virtual machine instances that can be found to be in an unhealthy state.
1162 - This check will happen after each batch is upgraded.
1163 - If this percentage is ever exceeded, the rolling update aborts.
1164 - The value of this field should be between 0 and 100, inclusive.
1165 type: int
1166 pause_time_between_batches:
1167 description:
1168 - The wait time between completing the update for all virtual machines in one batch and starting the next batch.
1169 - The time duration should be specified in ISO 8601 format.
1170 type: str
1171 prioritize_unhealthy_instances:
1172 description:
1173 - Upgrade all unhealthy instances in a scale set before any healthy instances.
1174 type: bool
1175 rollback_failed_instances_on_policy_breach:
1176 description:
1177 - Rollback failed instances to previous model if the Rolling Upgrade policy is violated.
1178 type: bool
1179 resource_tags:
1180 description:
1181 - The user-defined tags to be associated with the Azure Batch Pool.
1182 - When specified, these tags are propagated to the backing Azure resources associated with the pool.
1183 - This property can only be specified when the Batch account was created with the poolAllocationMode property set to 'UserSubscription'.
1184 type: dict
1185 is_disable_auto_scale:
1186 description:
1187 - Whether disables automatic scaling for a pool.
1188 type: bool
1189 default: false
1190 is_stop_resize:
1191 description:
1192 - Whether stops an ongoing resize operation on the pool.
1193 type: bool
1194 default: false
1195 state:
1196 description:
1197 - Assert the state of the Batch Account Pool.
1198 - Use C(present) to create or update a Batch Account Pool and C(absent) to delete it.
1199 default: present
1200 type: str
1201 choices:
1202 - present
1203 - absent
1204
1205 extends_documentation_fragment:
1206 - azure.azcollection.azure
1207
1208 author:
1209 - xuzhang3 (@xuzhang3)
1210 - Fred Sun (@Fred-sun)
1211 '''
1212
1213 EXAMPLES = '''
1214 - name: Create a new batch account pool
1215 azure_rm_batchaccountpool:
1216 resource_group: "{{ resource_group }}"
1217 batch_account_name: "{{ batch_account_name }}"
1218 name: "pool{{ batch_account_name }}--004"
1219 deployment_configuration:
1220 virtual_machine_configuration:
1221 image_reference:
1222 offer: ubuntu-hpc
1223 publisher: microsoft-dsvm
1224 sku: 2204
1225 version: latest
1226 node_agent_sku_id: batch.node.ubuntu 22.04
1227 node_placement_configuration:
1228 policy: Regional
1229 os_disk:
1230 caching: None
1231 managed_disk:
1232 storage_account_type: Premium_LRS
1233 display_name: "fredtest01"
1234 identity:
1235 type: UserAssigned
1236 user_assigned_identities:
1237 '/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/AzSecPackAutoConfigUA-westus':
1238 client_id: xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
1239 principal_id: yyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
1240 '/subscriptions/xxx-xxx/resourceGroups/yishitest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/ystestidentity':
1241 client_id: yyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
1242 principal_id: xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
1243 inter_node_communication: Disabled
1244 network_configuration:
1245 dynamic_vnet_assignment_scope: none
1246 subnet_id: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworks/vnet02/subnets/default"
1247 endpoint_configuration:
1248 inbound_nat_pools:
1249 - backend_port: 33
1250 frontend_port_range_end: 49999
1251 frontend_port_range_start: 1
1252 name: nat02
1253 protocol: UDP
1254 public_ip_address_configuration:
1255 provision: BatchManaged
1256 scale_settings:
1257 fixed_scale:
1258 resize_timeout: PT15M
1259 target_dedicated_nodes: 0
1260 target_low_priority_nodes: 0
1261 target_node_communication_mode: Default
1262 task_scheduling_policy:
1263 node_fill_type: Pack
1264 task_slots_per_node: 1
1265 vm_size: STANDARD_D2S_V3
1266 upgrade_policy:
1267 mode: manual
1268 rolling_upgrade_policy:
1269 max_batch_instance_percent: 20
1270 max_unhealthy_instance_percent: 20
1271 max_unhealthy_upgraded_instance_percent: 20
1272 pause_time_between_batches: P0D
1273 rollback_failed_instances_on_policy_breach: false
1274 automatic_os_upgrade_policy:
1275 disable_automatic_rollback: false
1276 enable_automatic_os_upgrade: false
1277 os_rolling_upgrade_deferral: false
1278 use_rolling_upgrade_policy: false
1279
1280 - name: Delete the Batch Account Pool
1281 azure_rm_batchaccountpool:
1282 resource_group: MyResGroup
1283 name: pool01
1284 batch_account_name: mybatchaccount
1285 state: absent
1286 '''
1287
1288 RETURN = '''
1289 state:
1290 description:
1291 - Contains information about an pool in a Batch account.
1292 type: dict
1293 returned: always
1294 sample: {
1295 "allocation_state": "Steady",
1296 "allocation_state_transition_time": "2024-11-05T08:58:16.803138Z",
1297 "batch_account_name": "fredbatch02",
1298 "creation_time": "2024-11-05T08:58:15.399345Z",
1299 "current_dedicated_nodes": 0,
1300 "current_low_priority_nodes": 0,
1301 "deployment_configuration": {
1302 "virtual_machine_configuration": {
1303 "image_reference": {
1304 "offer": "ubuntu-hpc",
1305 "publisher": "microsoft-dsvm",
1306 "sku": "2204",
1307 "version": "latest"
1308 },
1309 "node_agent_sku_id": "batch.node.ubuntu 22.04",
1310 "node_placement_configuration": {
1311 "policy": "Regional"
1312 },
1313 "os_disk": {
1314 "caching": "None",
1315 "managed_disk": {
1316 "storage_account_type": "Premium_LRS"
1317 }
1318 }
1319 }
1320 },
1321 "etag": "0x8DCFD77FC345CFE",
1322 "id": "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Batch/batchAccounts/batch01/pools/pool01",
1323 "inter_node_communication": "Disabled",
1324 "last_modified": "2024-11-05T08:58:15.399347Z",
1325 "name": "poolfredbatch02--002",
1326 "network_configuration": {
1327 "dynamic_vnet_assignment_scope": "None",
1328 "enable_accelerated_networking": false,
1329 "endpoint_configuration": {
1330 "inbound_nat_pools": [
1331 {
1332 "backend_port": 33,
1333 "frontend_port_range_end": 49999,
1334 "frontend_port_range_start": 1,
1335 "name": "nat02",
1336 "protocol": "UDP"
1337 }
1338 ]
1339 },
1340 "public_ip_address_configuration": {
1341 "provision": "BatchManaged"
1342 },
1343 "subnet_id": "/subscriptions/xxx-xxx/resourceGroups/testrg/providers/Microsoft.Network/virtualNetworks/vnet01/subnets/default"
1344 },
1345 "provisioning_state": "Succeeded",
1346 "provisioning_state_transition_time": "2024-11-05T08:58:15.399345Z",
1347 "resize_operation_status": {
1348 "node_deallocation_option": "Requeue",
1349 "resize_timeout": "PT15M",
1350 "start_time": "2024-11-05T08:58:15.399317Z",
1351 "target_dedicated_nodes": 0
1352 },
1353 "resource_group": "v-xisuRG06",
1354 "scale_settings": {
1355 "fixed_scale": {
1356 "resize_timeout": "PT15M",
1357 "target_dedicated_nodes": 0,
1358 "target_low_priority_nodes": 0
1359 }
1360 },
1361 "target_node_communication_mode": "Default",
1362 "task_scheduling_policy": {
1363 "node_fill_type": "Pack"
1364 },
1365 "task_slots_per_node": 1,
1366 "type": "Microsoft.Batch/batchAccounts/pools",
1367 "upgrade_policy": {
1368 "automatic_os_upgrade_policy": {
1369 "disable_automatic_rollback": false,
1370 "enable_automatic_os_upgrade": false,
1371 "os_rolling_upgrade_deferral": false,
1372 "use_rolling_upgrade_policy": false
1373 },
1374 "mode": "Manual",
1375 "rolling_upgrade_policy": {
1376 "max_batch_instance_percent": 20,
1377 "max_unhealthy_instance_percent": 20,
1378 "max_unhealthy_upgraded_instance_percent": 20,
1379 "pause_time_between_batches": "P0D",
1380 "rollback_failed_instances_on_policy_breach": false
1381 }
1382 },
1383 "vm_size": "STANDARD_D2S_V3"
1384 }
1385 '''
1386
1387 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt
1388
1389 try:
1390 from azure.core.polling import LROPoller
1391 from azure.core.exceptions import ResourceNotFoundError
1392 except ImportError:
1393 # This is handled in azure_rm_common
1394 pass
1395
1396
1397 class AzureRMBatchAccountPool(AzureRMModuleBaseExt):
1398 """Configuration class for an Azure RM Batch Account Pool resource"""
1399
1400 def __init__(self):
1401 self.module_arg_spec = dict(
1402 resource_group=dict(
1403 required=True,
1404 type='str'
1405 ),
1406 batch_account_name=dict(
1407 type='str',
1408 required=True,
1409 ),
1410 name=dict(
1411 required=True,
1412 type='str'
1413 ),
1414 identity=dict(
1415 type='dict',
1416 options=dict(
1417 type=dict(type='str', required=True, choices=['None', 'UserAssigned']),
1418 user_assigned_identities=dict(
1419 type='dict',
1420 )
1421 )
1422 ),
1423 display_name=dict(
1424 type='str'
1425 ),
1426 vm_size=dict(
1427 type='str'
1428 ),
1429 deployment_configuration=dict(
1430 type='dict',
1431 options=dict(
1432 cloud_service_configuration=dict(
1433 type='dict',
1434 options=dict(
1435 os_family=dict(type='str', default='*'),
1436 os_version=dict(type='str')
1437 )
1438 ),
1439 virtual_machine_configuration=dict(
1440 type='dict',
1441 options=dict(
1442 image_reference=dict(
1443 type='dict',
1444 required=True,
1445 options=dict(
1446 publisher=dict(type='str'),
1447 offer=dict(type='str'),
1448 sku=dict(type='str'),
1449 version=dict(type='str'),
1450 id=dict(type='str'),
1451 )
1452 ),
1453 node_agent_sku_id=dict(type='str', required=True),
1454 windows_configuration=dict(
1455 type='dict',
1456 options=dict(
1457 enable_automatic_updates=dict(type='bool', default=True)
1458 )
1459 ),
1460 data_disks=dict(
1461 type='list',
1462 elements='dict',
1463 options=dict(
1464 lun=dict(type='int', required=True),
1465 caching=dict(type='str', choices=['None', 'ReadOnly', 'ReadWrite']),
1466 disk_size_gb=dict(type='int', required=True),
1467 storage_account_type=dict(
1468 type='str',
1469 default='Standard_LRS',
1470 choices=['Standard_LRS', 'Premium_LRS', 'StandardSSD_LRS']
1471 )
1472 )
1473 ),
1474 license_type=dict(
1475 type='str'
1476 ),
1477 container_configuration=dict(
1478 type='dict',
1479 options=dict(
1480 type=dict(type='str', choices=['DockerCompatible', 'CriCompatible'], required=True),
1481 container_image_names=dict(type='list', elements='str'),
1482 container_registries=dict(
1483 type='list',
1484 elements='dict',
1485 options=dict(
1486 user_name=dict(type='str'),
1487 password=dict(type='str', no_log=True),
1488 registry_server=dict(type='str', default='docker.io'),
1489 identity_reference=dict(
1490 type='dict',
1491 options=dict(
1492 resource_id=dict(type='str')
1493 )
1494 )
1495 )
1496 )
1497 )
1498 ),
1499 disk_encryption_configuration=dict(
1500 type='dict',
1501 options=dict(
1502 targets=dict(type='list', elements='str', choices=['TemporaryDisk', 'OsDisk'])
1503 )
1504 ),
1505 node_placement_configuration=dict(
1506 type='dict',
1507 options=dict(
1508 policy=dict(
1509 type='str',
1510 choices=['Zonal', 'Regional']
1511 )
1512 ),
1513 ),
1514 extensions=dict(
1515 type='list',
1516 elements='dict',
1517 options=dict(
1518 name=dict(type='str', required=True),
1519 publisher=dict(type='str', required=True),
1520 type=dict(type='str', required=True),
1521 type_handler_version=dict(type='str'),
1522 auto_upgrade_minor_version=dict(type='bool'),
1523 enable_automatic_upgrade=dict(type='bool'),
1524 provision_after_extensions=dict(type='list', elements='str'),
1525 settings=dict(type='json'),
1526 protected_settings=dict(type='json')
1527 )
1528 ),
1529 os_disk=dict(
1530 type='dict',
1531 options=dict(
1532 caching=dict(
1533 type='str',
1534 choices=['ReadOnly', 'ReadWrite', 'None']
1535 ),
1536 write_accelerator_enabled=dict(type='bool'),
1537 disk_size_gb=dict(type='int'),
1538 managed_disk=dict(
1539 type='dict',
1540 options=dict(
1541 storage_account_type=dict(type='str', choices=["Standard_LRS", "Premium_LRS", "StandardSSD_LRS"])
1542 )
1543 ),
1544 ephemeral_os_disk_settings=dict(
1545 type='dict',
1546 options=dict(
1547 placement=dict(type='str')
1548 )
1549 )
1550 )
1551 ),
1552 security_profile=dict(
1553 type='dict',
1554 options=dict(
1555 security_type=dict(type='str', default='trustedLaunch'),
1556 encryption_at_host=dict(type='bool'),
1557 uefi_settings=dict(
1558 type='dict',
1559 options=dict(
1560 secure_boot_enabled=dict(type='bool'),
1561 v_tpm_enabled=dict(type='bool')
1562 )
1563 )
1564 )
1565 ),
1566 service_artifact_reference=dict(
1567 type='dict',
1568 options=dict(
1569 id=dict(type='str')
1570 )
1571 )
1572 )
1573 )
1574 )
1575 ),
1576 scale_settings=dict(
1577 type='dict',
1578 options=dict(
1579 fixed_scale=dict(
1580 type='dict',
1581 options=dict(
1582 resize_timeout=dict(type='str', default='P15M'),
1583 target_dedicated_nodes=dict(type='int'),
1584 target_low_priority_nodes=dict(type='int'),
1585 node_deallocation_option=dict(type='str', choices=["Requeue", "Terminate", "TaskCompletion", "RetainedData"])
1586 )
1587 ),
1588 auto_scale=dict(
1589 type='dict',
1590 options=dict(
1591 formula=dict(type='str', required=True),
1592 evaluation_interval=dict(type='str', default='P15M'),
1593 )
1594 )
1595 )
1596 ),
1597 inter_node_communication=dict(
1598 type='str',
1599 choices=['Enabled', 'Disabled']
1600 ),
1601 network_configuration=dict(
1602 type='dict',
1603 options=dict(
1604 subnet_id=dict(type='str'),
1605 dynamic_vnet_assignment_scope=dict(type='str', choices=['none', 'job']),
1606 endpoint_configuration=dict(
1607 type='dict',
1608 options=dict(
1609 inbound_nat_pools=dict(
1610 type='list',
1611 elements='dict',
1612 options=dict(
1613 name=dict(type='str', required=True),
1614 protocol=dict(type='str', choices=['UDP', 'TCP'], required=True),
1615 backend_port=dict(type='int', required=True),
1616 frontend_port_range_start=dict(type='int', required=True),
1617 frontend_port_range_end=dict(type='int', required=True),
1618 network_security_group_rules=dict(
1619 type='list',
1620 elements='dict',
1621 options=dict(
1622 priority=dict(type='int', required=True),
1623 access=dict(type='str', required=True, choices=['Allow', 'Deny']),
1624 source_address_prefix=dict(type='str'),
1625 source_port_ranges=dict(type='list', elements='str')
1626 )
1627 )
1628 )
1629 )
1630 )
1631 ),
1632 public_ip_address_configuration=dict(
1633 type='dict',
1634 options=dict(
1635 provision=dict(type='str', default='BatchManaged', choices=['BatchManaged', 'UserManaged', 'NoPublicIPAddresses']),
1636 ip_address_ids=dict(
1637 type='list',
1638 elements='str'
1639 )
1640 )
1641 ),
1642 enable_accelerated_networking=dict(
1643 type='bool'
1644 )
1645 )
1646 ),
1647 task_slots_per_node=dict(
1648 type='int',
1649 default=1
1650 ),
1651 task_scheduling_policy=dict(
1652 type='dict',
1653 options=dict(
1654 node_fill_type=dict(type='str', choices=['Spread', 'Pack'])
1655 )
1656 ),
1657 user_accounts=dict(
1658 type='list',
1659 elements='dict',
1660 options=dict(
1661 name=dict(type='str', required=True),
1662 password=dict(type='str', required=True, no_log=True),
1663 elevation_level=dict(type='str', choices=['NonAdmin', 'Admin'], default='NonAdmin'),
1664 linux_user_configuration=dict(
1665 type='dict',
1666 options=dict(
1667 uid=dict(type='int',),
1668 gid=dict(type='int'),
1669 ssh_private_key=dict(type='str', no_log=True),
1670 )
1671 ),
1672 windows_user_configuration=dict(
1673 type='dict',
1674 options=dict(
1675 login_mode=dict(type='str', choices=['Batch', 'Interactive'])
1676 )
1677 )
1678 )
1679 ),
1680 metadata=dict(
1681 type='list',
1682 elements='dict',
1683 options=dict(
1684 name=dict(type='str', required=True),
1685 value=dict(type='str', required=True)
1686 )
1687 ),
1688 start_task=dict(
1689 type='dict',
1690 options=dict(
1691 command_line=dict(type='str'),
1692 resource_files=dict(
1693 type='list',
1694 elements='dict',
1695 options=dict(
1696 auto_storage_container_name=dict(type='str'),
1697 storage_container_url=dict(type='str'),
1698 http_url=dict(type='str'),
1699 blob_prefix=dict(type='str'),
1700 file_path=dict(type='str'),
1701 file_mode=dict(type='str'),
1702 identity_reference=dict(
1703 type='dict',
1704 options=dict(
1705 resource_id=dict(type='str')
1706 )
1707 )
1708 )
1709 ),
1710 environment_settings=dict(
1711 type='list',
1712 elements='dict',
1713 options=dict(
1714 name=dict(type='str', required=True),
1715 value=dict(type='str')
1716 )
1717 ),
1718 user_identity=dict(
1719 type='dict',
1720 options=dict(
1721 user_name=dict(type='str'),
1722 auto_user=dict(
1723 type='dict',
1724 options=dict(
1725 scope=dict(type='str', default='Pool', choices=['Pool', 'Task']),
1726 elevation_level=dict(type='str', default='NonAdmin', choices=['NonAdmin', 'Admin'])
1727 )
1728 )
1729 )
1730 ),
1731 max_task_retry_count=dict(
1732 type='int',
1733 default=0,
1734 ),
1735 wait_for_success=dict(type='bool'),
1736 container_settings=dict(
1737 type='dict',
1738 options=dict(
1739 container_run_options=dict(type='str'),
1740 image_name=dict(type='str'),
1741 working_directory=dict(type='str', choices=['TaskWorkingDirectory', 'ContainerImageDefault']),
1742 registry=dict(
1743 type='dict',
1744 options=dict(
1745 user_name=dict(type='str'),
1746 password=dict(type='str', no_log=True),
1747 registry_server=dict(type='str', default='docker.io'),
1748 identity_reference=dict(
1749 type='dict',
1750 options=dict(
1751 resource_id=dict(type='str')
1752 )
1753 )
1754 )
1755 )
1756 )
1757 )
1758 )
1759 ),
1760 application_packages=dict(
1761 type='list',
1762 elements='dict',
1763 options=dict(
1764 id=dict(type='str', required=True),
1765 version=dict(type='str')
1766 )
1767 ),
1768 certificates=dict(
1769 type='list',
1770 elements='dict',
1771 options=dict(
1772 id=dict(type='str', required=True),
1773 store_location=dict(type='str', default='CurrentUser', choices=['CurrentUser', 'LocalMachine']),
1774 store_name=dict(
1775 type='str',
1776 default='My',
1777 choices=['My', 'Root', 'CA', 'Trust', 'Disallowed', 'TrustedPeople', 'TrustedPublisher', 'AuthRoot', 'AddressBook']
1778 ),
1779 visibility=dict(type='list', elements='str', choices=['StartTask', 'Task', 'RemoteUser'])
1780 )
1781 ),
1782 application_licenses=dict(
1783 type='list',
1784 elements='str'
1785 ),
1786 mount_configuration=dict(
1787 type='list',
1788 elements='dict',
1789 options=dict(
1790 azure_blob_file_system_configuration=dict(
1791 type='dict',
1792 options=dict(
1793 account_name=dict(type='str', required=True),
1794 container_name=dict(type='str', required=True),
1795 account_key=dict(type='str', no_log=True),
1796 sas_key=dict(type='str', no_log=True),
1797 blobfuse_options=dict(type='str', choices=['net use', 'mount']),
1798 relative_mount_path=dict(type='str', required=True),
1799 identity_reference=dict(
1800 type='dict',
1801 options=dict(
1802 resource_id=dict(type='str')
1803 )
1804 )
1805 )
1806 ),
1807 nfs_mount_configuration=dict(
1808 type='dict',
1809 options=dict(
1810 source=dict(type='str', required=True),
1811 relative_mount_path=dict(type='str', required=True),
1812 mount_options=dict(type='str', choices=['net use', 'mount'])
1813 )
1814 ),
1815 cifs_mount_configuration=dict(
1816 type='dict',
1817 options=dict(
1818 user_name=dict(type='str', required=True),
1819 source=dict(type='str', required=True),
1820 relative_mount_path=dict(type='str', required=True),
1821 mount_options=dict(type='str', choices=['net use', 'mount']),
1822 password=dict(type='str', no_log=True, required=True)
1823 )
1824 ),
1825 azure_file_share_configuration=dict(
1826 type='dict',
1827 options=dict(
1828 account_name=dict(type='str', required=True),
1829 azure_file_url=dict(type='str', required=True),
1830 account_key=dict(type='str', required=True, no_log=True),
1831 relative_mount_path=dict(type='str', required=True),
1832 mount_options=dict(type='str', choices=['net use', 'mount'])
1833 )
1834 )
1835 )
1836 ),
1837 target_node_communication_mode=dict(
1838 type='str',
1839 default='Default',
1840 choices=["Default", "Classic", "Simplified"]
1841 ),
1842 upgrade_policy=dict(
1843 type='dict',
1844 options=dict(
1845 mode=dict(type='str', required=True, choices=['automatic', 'manual', 'rolling']),
1846 automatic_os_upgrade_policy=dict(
1847 type='dict',
1848 options=dict(
1849 disable_automatic_rollback=dict(type='bool'),
1850 enable_automatic_os_upgrade=dict(type='bool'),
1851 use_rolling_upgrade_policy=dict(type='bool'),
1852 os_rolling_upgrade_deferral=dict(type='bool'),
1853 )
1854 ),
1855 rolling_upgrade_policy=dict(
1856 type='dict',
1857 options=dict(
1858 enable_cross_zone_upgrade=dict(type='bool'),
1859 max_batch_instance_percent=dict(type='int'),
1860 max_unhealthy_instance_percent=dict(type='int'),
1861 max_unhealthy_upgraded_instance_percent=dict(type='int'),
1862 pause_time_between_batches=dict(type='str'),
1863 prioritize_unhealthy_instances=dict(type='bool'),
1864 rollback_failed_instances_on_policy_breach=dict(type='bool')
1865 )
1866 )
1867 )
1868 ),
1869 resource_tags=dict(
1870 type='dict',
1871 ),
1872 is_disable_auto_scale=dict(
1873 type='bool',
1874 default=False
1875 ),
1876 is_stop_resize=dict(
1877 type='bool',
1878 default=False
1879 ),
1880 state=dict(
1881 type='str',
1882 default='present',
1883 choices=['present', 'absent']
1884 )
1885 )
1886
1887 self.batch_account_name = None
1888 self.name = None
1889 self.resource_group = None
1890 self.is_disable_auto_scale = None
1891 self.is_stop_resize = None
1892 self.results = dict(changed=False)
1893 self.state = None
1894 self.body = dict()
1895
1896 super(AzureRMBatchAccountPool, self).__init__(derived_arg_spec=self.module_arg_spec,
1897 supports_check_mode=True,
1898 supports_tags=False)
1899
1900 def exec_module(self, **kwargs):
1901 """Main module execution method"""
1902
1903 for key in list(self.module_arg_spec.keys()):
1904 if hasattr(self, key):
1905 setattr(self, key, kwargs[key])
1906 elif kwargs[key] is not None:
1907 self.body[key] = kwargs[key]
1908
1909 response = None
1910 changed = False
1911
1912 old_response = self.get_batchaccount_pool()
1913
1914 if not old_response:
1915 self.log("Batch Account Pool instance doesn't exist")
1916 if self.state == 'absent':
1917 self.log("Old instance didn't exist")
1918 else:
1919 changed = True
1920 if not self.check_mode:
1921 response = self.create_batchaccount_pool()
1922 else:
1923 self.log("Batch Account Pool instance already exists")
1924 if self.state == 'absent':
1925 if not self.check_mode:
1926 changed = True
1927 response = self.delete_batchaccount_pool()
1928 else:
1929 if not self.default_compare({}, self.body, old_response, '', dict(compare=[])):
1930 changed = True
1931 if not self.check_mode and changed:
1932 response = self.update_batchaccount_pool()
1933 if self.is_stop_resize and not self.check_mode:
1934 changed = True
1935 self.stop_resize_pool()
1936 if self.is_disable_auto_scale and not self.check_mode:
1937 changed = True
1938 self.disable_auto_scale_pool()
1939
1940 self.results = dict(
1941 changed=changed,
1942 state=self.get_batchaccount_pool(),
1943 )
1944 return self.results
1945
1946 def create_batchaccount_pool(self):
1947 '''
1948 Creates Batch Account Pool with the specified configuration.
1949 '''
1950 self.log("Creating the Batch Account Pool instance {0}".format(self.name))
1951
1952 try:
1953 response = self.batch_account_client.pool.create(resource_group_name=self.resource_group,
1954 account_name=self.batch_account_name,
1955 pool_name=self.name,
1956 parameters=self.batch_account_model.Pool(**self.body))
1957 if isinstance(response, LROPoller):
1958 response = self.get_poller_result(response)
1959 except Exception as exc:
1960 self.log('Error attempting to create the Batch Account Pool instance.')
1961 self.fail("Error creating the Batch Account Pool instance: {0}".format(str(exc)))
1962 return response.as_dict()
1963
1964 def update_batchaccount_pool(self):
1965 '''
1966 Update Batch Account Pool with the specified configuration.
1967 '''
1968 self.log("Updating the Batch Account Pool instance {0}".format(self.name))
1969
1970 try:
1971 response = self.batch_account_client.pool.update(resource_group_name=self.resource_group,
1972 account_name=self.batch_account_name,
1973 pool_name=self.name,
1974 parameters=self.batch_account_model.Pool(**self.body))
1975 if isinstance(response, LROPoller):
1976 response = self.get_poller_result(response)
1977 except Exception as exc:
1978 self.log('Error attempting to update the Batch Account Pool instance.')
1979 self.fail("Error updating the Batch Account Pool instance: {0}".format(str(exc)))
1980 return response.as_dict()
1981
1982 def disable_auto_scale_pool(self):
1983 '''
1984 Disable_auto_scale Batch Account Pool instance in the specified subscription and resource group.
1985 :return: True
1986 '''
1987 self.log("Disable_auto_scale the Batch Account Pool instance {0}".format(self.name))
1988 try:
1989 response = self.batch_account_client.pool.disable_auto_scale(resource_group_name=self.resource_group,
1990 account_name=self.batch_account_name,
1991 pool_name=self.name)
1992 except Exception as e:
1993 self.log('Error attempting to disable the Batch Account Pool auto_scale.')
1994 self.fail("Error disable the Batch Account Pool auto_scale instance: {0}".format(str(e)))
1995 return True
1996
1997 def stop_resize_pool(self):
1998 '''
1999 Stop resize Batch Account Pool instance in the specified subscription and resource group.
2000 :return: True
2001 '''
2002 self.log("Stop the Batch Account Pool resize {0}".format(self.name))
2003 try:
2004 response = self.batch_account_client.pool.stop_resize(resource_group_name=self.resource_group,
2005 account_name=self.batch_account_name,
2006 pool_name=self.name)
2007 except Exception as e:
2008 self.log('Error attempting to stop the Batch Account Pool resize.')
2009 self.fail("Error stop the Batch Account Pool resize: {0}".format(str(e)))
2010 return True
2011
2012 def delete_batchaccount_pool(self):
2013 '''
2014 Deletes specified Batch Account Pool instance in the specified subscription and resource group.
2015 :return: True
2016 '''
2017 self.log("Deleting the Batch Account Pool instance {0}".format(self.name))
2018 try:
2019 response = self.batch_account_client.pool.begin_delete(resource_group_name=self.resource_group,
2020 account_name=self.batch_account_name,
2021 pool_name=self.name)
2022 except Exception as e:
2023 self.log('Error attempting to delete the Batch Account Pool instance.')
2024 self.fail("Error deleting the Batch Account Pool instance: {0}".format(str(e)))
2025
2026 return True
2027
2028 def get_batchaccount_pool(self):
2029 '''
2030 Gets the properties of the specified Batch Account Pool
2031 :return: deserialized Batch Account Pool instance state dictionary
2032 '''
2033 self.log("Checking if the Batch Account Pool instance {0} is present".format(self.name))
2034 found = False
2035 try:
2036 response = self.batch_account_client.pool.get(resource_group_name=self.resource_group,
2037 account_name=self.batch_account_name,
2038 pool_name=self.name)
2039 found = True
2040 self.log("Response : {0}".format(response))
2041 self.log("Batch Account Pool instance : {0} found".format(response.name))
2042 except ResourceNotFoundError as e:
2043 self.log('Did not find the Batch Account Pool instance. Exception as {0}'.format(e))
2044 if found is True:
2045 return self.format_item(response.as_dict())
2046 return False
2047
2048 def format_item(self, item):
2049 if item is None:
2050 return
2051 result = item
2052 result['resource_group'] = self.resource_group
2053 result['batch_account_name'] = self.batch_account_name
2054 return result
2055
2056
2057 def main():
2058 """Main execution"""
2059 AzureRMBatchAccountPool()
2060
2061
2062 if __name__ == '__main__':
2063 main()