diff --git a/plugins/modules/azure_rm_virtualmachine.py b/plugins/modules/azure_rm_virtualmachine.py index 885a88d6a..e2dd85099 100644 --- a/plugins/modules/azure_rm_virtualmachine.py +++ b/plugins/modules/azure_rm_virtualmachine.py @@ -151,6 +151,8 @@ description: - The image used to build the VM. - For custom images, the name of the image. To narrow the search to a specific resource group, a dict with the keys I(name) and I(resource_group). + - For community images, a dict with the keys I(community_gallery_image_id). Specified the community gallery image unique id for vm demployment. + - The I(community_gallery_image_id) can be fetched from shared gallery image GET call. - For Marketplace images, a dict with the keys I(publisher), I(offer), I(sku), and I(version). - Set I(version=latest) to get the most recent version of a given image. - Required when creating. @@ -840,6 +842,22 @@ sku: 20_04-lts version: latest +- name: Create VM with cummunity gallery image ID + azure_rm_virtualmachine: + resource_group: "{{ resource_group }}" + name: "communit-image-vm" + admin_username: testuser + ssh_password_enabled: false + managed_disk_type: Premium_LRS + open_ports: + - 33 + ssh_public_keys: + - path: /home/testuser/.ssh/authorized_keys + key_data: "ssh-rsa ************* @qq.com" + vm_size: Standard_B1ms + image: + community_gallery_image_id: "/CommunityGalleries/yellowbrick-fc7e81f1-87dd-4989-9ca8-03743762e873/Images/Ubuntu-5.15.0-1035-azure_22.04" + - name: Power Off azure_rm_virtualmachine: resource_group: myResourceGroup @@ -1440,6 +1458,8 @@ def exec_module(self, **kwargs): sku=self.image['sku'], version=self.image['version'] ) + elif self.image.get('community_gallery_image_id') is not None: + image_reference = self.compute_models.ImageReference(community_gallery_image_id=self.image['community_gallery_image_id']) elif self.image.get('name'): custom_image = True image_reference = self.get_custom_image_reference( @@ -2194,6 +2214,10 @@ def exec_module(self, **kwargs): image_reference = self.compute_models.ImageReference( id=vm_dict['storage_profile']['image_reference']['id'] ) + elif 'community_gallery_image_id' in vm_dict['storage_profile'].keys(): + image_reference = self.compute_models.ImageReference( + community_gallery_image_id=vm_dict['storage_profile']['image_reference']['community_gallery_image_id'] + ) else: image_reference = self.compute_models.ImageReference( publisher=vm_dict['storage_profile']['image_reference'].get('publisher'), diff --git a/plugins/modules/azure_rm_virtualmachine_info.py b/plugins/modules/azure_rm_virtualmachine_info.py index 14d46fe48..46fb63504 100644 --- a/plugins/modules/azure_rm_virtualmachine_info.py +++ b/plugins/modules/azure_rm_virtualmachine_info.py @@ -194,6 +194,12 @@ type: str returned: when created from custom image sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage + community_gallery_image_id: + description: + - The community gallery image unique id for vm deployment. + type: str + returned: when created from community gallery image + sample: "/CommunityGalleries/yellowbrick-fc7e81f1-87dd-4989-9ca8-03743762e873/Images/Ubuntu-5.15.0-1035-azure_22.04" location: description: - Resource location. @@ -540,6 +546,10 @@ def serialize_vm(self, vm): 'offer': image['offer'], 'version': image['version'] } + elif image.get('community_gallery_image_id') is not None: + new_result['image'] = { + 'community_gallery_image_id': image.get('community_gallery_image_id') + } else: new_result['image'] = { 'id': image.get('id', None) diff --git a/plugins/modules/azure_rm_virtualmachinescaleset.py b/plugins/modules/azure_rm_virtualmachinescaleset.py index ddf9cd475..4db273a38 100644 --- a/plugins/modules/azure_rm_virtualmachinescaleset.py +++ b/plugins/modules/azure_rm_virtualmachinescaleset.py @@ -131,6 +131,8 @@ - If a dict with the keys I(name) and I(resource_group), the image is sourced from a custom image based on the I(name) and I(resource_group) set. Note that the key I(resource_group) is optional and if omitted, all images in the subscription will be searched for by I(name). - Custom image support was added in Ansible 2.5. + - For community images, a dict with the keys I(community_gallery_image_id). Specified the community gallery image unique id for vm demployment. + - The I(community_gallery_image_id) can be fetched from shared gallery image GET call. - Required when creating. type: raw os_disk_caching: @@ -449,6 +451,32 @@ managed_disk_type: Standard_LRS image: customimage001 +- name: Create a VMSS with a community gallery image ID + azure_rm_virtualmachinescaleset: + resource_group: myResourceGroup + name: testvmss + vm_size: Standard_D8_v4 + admin_username: testuser + single_placement_group: false + platform_fault_domain_count: 1 + public_ip_per_vm: true + ssh_password_enabled: false + ssh_public_keys: + - path: /home/testuser/.ssh/authorized_keys + key_data: "ssh-rsa ********* xiuxi.sun@qq.com" + virtual_network_name: VMSStestVnet + subnet_name: VMSStestSubnet + managed_disk_type: Standard_LRS + orchestration_mode: Flexible + os_disk_caching: ReadWrite + image: + community_gallery_image_id: "/CommunityGalleries/yellowbrick-fc7e81f1-87dd-4989-9ca8-03743762e873/Images/Ubuntu-5.15.0-1035-azure_22.04" + data_disks: + - lun: 0 + disk_size_gb: 64 + caching: ReadWrite + managed_disk_type: Standard_LRS + - name: Create a VMSS with over 100 instances azure_rm_virtualmachinescaleset: resource_group: myResourceGroup @@ -899,6 +927,11 @@ def exec_module(self, **kwargs): image_reference = self.compute_models.ImageReference(id=self.image['id']) except Exception as exc: self.fail("id Error: Cannot get image from the reference id - {0}".format(self.image['id'])) + elif self.image.get('community_gallery_image_id'): + try: + image_reference = self.compute_models.ImageReference(community_gallery_image_id=self.image['community_gallery_image_id']) + except Exception as exc: + self.fail("id Error: Cannot get image from the cummunity gallery image id- {0}".format(self.image['community_gallery_image_id'])) else: self.fail("parameter error: expecting image to contain [publisher, offer, sku, version], [name, resource_group] or [id]") elif self.image and isinstance(self.image, str): diff --git a/plugins/modules/azure_rm_virtualmachinescaleset_info.py b/plugins/modules/azure_rm_virtualmachinescaleset_info.py index 461afe4ed..0b3d0add3 100644 --- a/plugins/modules/azure_rm_virtualmachinescaleset_info.py +++ b/plugins/modules/azure_rm_virtualmachinescaleset_info.py @@ -159,27 +159,39 @@ offer: description: - The offer of the platform image or marketplace image used to create the virtual machine. - returned: always + returned: when created from marketplace image type: str sample: RHEL publisher: description: - Publisher name. - returned: always + returned: when created from marketplace image type: str sample: RedHat sku: description: - SKU name. - returned: always + returned: when created from marketplace image type: str sample: 7-RAW version: description: - Image version. - returned: always + returned: when created from marketplace image type: str sample: 7.5.2018050901 + id: + description: + - Custom image resource ID. + type: str + returned: when created from custom image + sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage + community_gallery_image_id: + description: + - The community gallery image unique id for vm deployment. + type: str + returned: when created from community gallery image + sample: "/CommunityGalleries/yellowbrick-fc7e81f1-87dd-4989-9ca8-03743762e873/Images/Ubuntu-5.15.0-1035-azure_22.04" load_balancer: description: - Load balancer name.