azure
azure copied to clipboard
vm from existing managed disk
How to create a VM from an existing managed disk? We have a VHD that we'd like to convert to a managed disk and deploy the VM. Not seeing any documentation on that.
- name: Create managed disk from vhd
azure_rm_manageddisk:
name: "{{ vm_name }}-OS"
location: "{{ Region }}"
resource_group: "{{ ResourceGroup }}"
create_option: import
source_uri: "{{ vhd_uri }}"
os_type: linux
storage_account_type: Premium_LRS
state: present
- name: Create Virtual Appliance
azure_rm_virtualmachine:
state: present
resource_group: "{{ ResourceGroup }}"
name: "{{ vm_name }}"
vm_size: "{{ vm_size }}"
network_interfaces: "{{ vm_nic_1 }}"
os_disk_name: "{{vm_name}}-OS"
managed_disk_type: "Premium_LRS"
boot_diagnostics:
enabled: "yes"
storage_account: "{{ diag_name }}"
availability_set: "{{ avs_name }}"
@DII-dsward Can you try the following way? Thank you very much!
- name: Create Resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: eastus
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ network_name }}"
address_prefixes: 10.42.0.0/24
- name: Create subnet
azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: "{{ subnet_name }}"
address_prefix: 10.42.0.0/28
virtual_network: "{{ network_name }}"
- name: Create managed disk from vhd
azure_rm_manageddisk:
name: "{{ vm_name }}-OS"
location: "{{ Region }}"
resource_group: "{{ ResourceGroup }}"
create_option: import
source_uri: "{{ vhd_uri }}"
os_type: linux
storage_account_type: Premium_LRS
state: present
register: output
- name: Create a VM multiple data managed disks
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
vm_size: Standard_D4s_v3
managed_disk_type: Standard_LRS
admin_username: *****
admin_password: ******
ssh_public_keys:
- path: /home/azureuser/.ssh/authorized_keys
key_data: "ssh-rsa ****************"
image:
offer: UbuntuServer
publisher: Canonical
sku: 18.04-LTS
version: latest
data_disks:
- lun: 0
disk_size_gb: 1024
managed_disk_id: "{{ output.state.id }}"
@DII-dsward You may attach the disk to VM by azure_rm_manageddisk.py, Does this meet your means?
- name: attach data disk
azure_rm_manageddisk:
name: "{{ disk_name }}"
resource_group: "{{ resource_group }}"
disk_size_gb: 1024
attach_caching: read_only
managed_by: "{{ virtual_machine.vm_name }}"
zone: 1
kindly ping!