Open ValioSV opened 2 years ago
@ValioSV I tested it locally, your Playbook is missing the required parameter "disk_size_gb ", and I got a VM disk type of" StandardSSD_LRS ". Can you try again here? And share the entire testing process, which will help solve any problems you encounter! Thank you very much!.
"data_disks": [
{
"caching": "ReadOnly",
"disk_size_gb": 128,
"lun": 0,
"managed_disk_id": "/subscriptions/xxxx/resourceGroups/v-xxxx/providers/Microsoft.Compute/disks/testvm02-datadisk-0",
"managed_disk_type": "StandardSSD_LRS",
"name": "testvm02-datadisk-0"
}
]
@Fred-sun I will try with the parameter "name" and "caching" added. I already tried with parameter "disk_size_gb" and with "create_option: FromImage" but it fails. The thing here is that I am creating a new VM from template and the LUNs are predefined in the Azure template so I do not have the "managed_disk_id". In the "Create VM" task above I am specifying: image: id: "{{ image_id }}" I tried many variations but it never sets the LUN to "StandardSSD_LRS". If you create a new data disk upfront and then attach it to the VM probably it works but this is not what I need.
@ValioSV Sorry, I still don't understand what you mean. Do you want to mount the existing disk to the VM?
@Fred-sun No I do not want to mount existing disks. I have a custom template created in Azure cloud and I am using it to deploy the VM using "azure_rm_virtualmachine". This custom template has 4 additional data disks (LUNs) already created and configured. So when I call the deploy from template in ansible it simply creates a new machine with one OS disk and 4 LUNs. The problem is that the LUNs are of type "Premium_SDD" and not "StandardSSD_LRS".
@ValioSV But from your description above, there is no mention of templates? Can you provide templates and Playbook? Will this help solve the problem you are having? Thank you very much!
@Fred-sun It is all described in the summary of the issue: "I cannot set "managed_disk_type" property to "StandardSSD_LRS" when creating a VM from custom image." See above. I have already provided the ansible role(create-vm-azure) above. Now I added the playbook too. See above in the description of the issue. Unfortunately I cannot provide the custom image from Azure because of company policies. I do not think the custom image makes any difference. Probably this will be reproduced with any custom image that you may have available.
@ValioSV Understand your problem! Now, when we create a VM using "custom image", it will be created according to the VM configuration of the image. we cannot create other disks when we create it. But at the end of creation, we can add the required data disks to the VM via the "azure_rm_mangeddisk.py" module! Thank you very much!
like this:
- name: Attach new disk to VM
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "{{ new_disk_name }}"
disk_size_gb: 1024
storage_account_type: StandardSSD_LRS
managed_by: "{{ vm_name }}"
@Fred-sun I have tried that and it does not work. In addition, I do not want to create a new disk for the VM but I want to change the type from the custom image while deploying a new instance. I did a little experiment. I created a new VM with one disk. Then I tried to change its type using ansible like this:
- name: Test data disks
hosts: localhost
connection: local
vars:
resource_group: LamaDevLandscape
disk_id: testvm1_OsDisk_1_1abea8cf190e4ebcab3fdd020fd311eb
vm_name: testvm1
collections:
- azure.azcollection
tasks:
- name: Detach the disk from the VM
azure_rm_manageddisk:
name: "{{ disk_id }}"
location: westeurope
resource_group: "{{ resource_group }}"
managed_by: "{{ vm_name }}"
- name: Change data disks type
azure_rm_manageddisk:
name: "{{ disk_id }}"
location: westeurope
resource_group: "{{ resource_group }}"
state: present
storage_account_type: StandardSSD_LRS
disk_size_gb: 30
managed_by: "{{ vm_name }}"
- name: Attach the disk to the VM
azure_rm_manageddisk:
name: "{{ disk_id }}"
location: westeurope
resource_group: "{{ resource_group }}"
attach_caching: read_only
disk_size_gb: 64
lun: 0
state: present
managed_by: "{{ vm_name }}"
It fails with the following error:
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/lroot/.ansible/tmp/ansible-tmp-1662641019.7764714-25633-21163196332198/ > /dev/null 2>&1 && sleep 0' The full traceback is: File "/tmp/ansible_azure_rm_manageddisk_payloadzyxpw3v/ansible_azure_rm_manageddisk_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_manageddisk.py", line 470, in create_or_update_managed_disk File "/home/lroot/.local/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 73, in wrapper_use_tracer return func(*args, **kwargs) File "/home/lroot/.local/lib/python3.10/site-packages/azure/mgmt/compute/v2021_04_01/operations/_disks_operations.py", line 430, in begin_create_or_update raw_result = self._create_or_update_initial( File "/home/lroot/.local/lib/python3.10/site-packages/azure/mgmt/compute/v2021_04_01/operations/_disks_operations.py", line 374, in _create_or_update_initial map_error(status_code=response.status_code, response=response, error_map=error_map) File "/home/lroot/.local/lib/python3.10/site-packages/azure/core/exceptions.py", line 105, in map_error raise error fatal: [localhost]: FAILED! => { "changed": false, "invocation": { "module_args": { "ad_user": null, "adfs_authority_url": null, "api_profile": "latest", "append_tags": true, "attach_caching": null, "auth_source": "auto", "cert_validation_mode": null, "client_id": null, "cloud_environment": "AzureCloud", "create_option": null, "disk_size_gb": 30, "location": "westeurope", "log_mode": null, "log_path": null, "lun": null, "managed_by": "testvm1", "name": "testvm1_OsDisk_1_1abea8cf190e4ebcab3fdd020fd311eb", "os_type": null, "password": null, "profile": null, "resource_group": "LamaDevLandscape", "secret": null, "source_uri": null, "state": "present", "storage_account_type": "StandardSSD_LRS", "subscription_id": null, "tags": null, "tenant": null, "zone": null } }, "msg": "Error creating the managed disk: (OperationNotAllowed) Cannot change account type, fault domain or network spine of disk testvm1_OsDisk_1_1abea8cf190e4ebcab3fdd020fd311eb while it is attached to running VM /subscriptions/49e39056-98af-4714-9d1d-7376dd148a23/resourceGroups/LamaDevLandscape/providers/Microsoft.Compute/virtualMachines/testvm1.\nCode: OperationNotAllowed\nMessage: Cannot change account type, fault domain or network spine of disk testvm1_OsDisk_1_1abea8cf190e4ebcab3fdd020fd311eb while it is attached to running VM /subscriptions/49e39056-98af-4714-9d1d-7376dd148a23/resourceGroups/LamaDevLandscape/providers/Microsoft.Compute/virtualMachines/testvm1." }
@ValioSV OK! I will test your idear and share result to you!
@ValioSV I understand your means. Because the image cannot be parsed for the time being, it cannot set the type of data disk in the module. We will tracking it. Thank you very much!
SUMMARY
I cannot set "managed_disk_type" property to "StandardSSD_LRS" when creating a VM from custom image.
ISSUE TYPE
COMPONENT NAME
azure.azcollection.azure_rm_virtualmachine module > managed_disk_type
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
SUSE Linux Enterprise Server 15 SP2
STEPS TO REPRODUCE
I am using ansible-playbook and roles. Below is the code of the tasks for creating a VM:
Role (create-vm-azure):
Playbook:
EXPECTED RESULTS
The VM is created with data disks type "StandardSSD_LRS"
ACTUAL RESULTS
The VM is created with data disks type "Premium_SDD"