azure_rm_virtualmachine
Manage Azure virtual machines
Collection: azure.azcollection
Full Name: azure.azcollection.azure_rm_virtualmachine
Synopsis
Manage Azure virtual machines
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| accept_terms | bool | false | Accept terms for Marketplace images that require it. | |
| Only Azure service admin/account admin users can purchase images from the Marketplace. | ||||
| Only valid when a I(plan) is specified. | ||||
| ad_user | string | Active Directory username. Use when authenticating with an Active Directory user rather than service principal. | ||
| additional_capabilities | dict | Enables or disables a capability on the virtual machine. | ||
| adfs_authority_url | string | Azure AD authority url. Use when authenticating with Username/password, and has your own ADFS authority. | ||
| admin_password | string | Password for the admin username. | ||
| Not required if the I(os_type=Linux) and SSH password authentication is disabled by setting I(ssh_password_enabled=false). | ||||
| admin_username | string | Admin username used to access the VM after it is created. | ||
| Required when creating a VM, except when I(specialized_image=true) or I(swap_os_disk) is set - in those cases the OS user identities are already baked into the source image or disk. | ||||
| allocated | bool | true | Whether the VM is allocated or deallocated, only useful with I(state=present). | |
| api_profile | string | latest | Selects an API profile to use when communicating with Azure services. Default value of C(latest) is appropriate for public clouds; future values will allow use with Azure Stack. | |
| append_tags | bool | true | Use to control if tags field is canonical or just appends to existing tags. | |
| When canonical, any tags not found in the tags parameter will be removed from the object’s metadata. | ||||
| auth_source | string | auto | Controls the source of the credentials to use for authentication. | |
| Can also be set via the C(ANSIBLE_AZURE_AUTH_SOURCE) environment variable. | ||||
| When set to C(auto) (the default) the precedence is module parameters -> C(env) -> C(credential_file) -> C(cli). | ||||
| When set to C(env), the credentials will be read from the environment variables. | ||||
| When set to C(credential_file), it will read the profile from C(~/.azure/credentials). | ||||
| When set to C(cli), the credentials will be sources from the Azure CLI profile. C(subscription_id) or the environment variable C(AZURE_SUBSCRIPTION_ID) can be used to identify the subscription ID if more than one is present otherwise the default az cli subscription is used. | ||||
| When set to C(msi), the host machine must be an azure resource with an enabled MSI extension. C(subscription_id) or the environment variable C(AZURE_SUBSCRIPTION_ID) can be used to identify the subscription ID if the resource is granted access to more than one subscription, otherwise the first subscription is chosen. | ||||
| The C(msi) was added in Ansible 2.6. | ||||
| availability_set | string | Name or ID of an existing availability set to add the VM to. The I(availability_set) should be in the same resource group as VM. | ||
| boot_diagnostics | dict | Manage boot diagnostics settings for a VM. | ||
| Boot diagnostics includes a serial console and remote console screenshots. | ||||
| capacity_reservation_group | dict | The name or ID of the capacity reservation group to be associated with. | ||
| cert_validation_mode | string | Controls the certificate validation behavior for Azure endpoints. By default, all modules will validate the server certificate, but when an HTTPS proxy is in use, or against Azure Stack, it may be necessary to disable this behavior by passing C(ignore). Can also be set via credential file profile or the C(AZURE_CERT_VALIDATION) environment variable. | ||
| client_id | string | Azure client ID. Use when authenticating with a Service Principal or Managed Identity (msi). | ||
| Can also be set via the C(AZURE_CLIENT_ID) environment variable. | ||||
| cloud_environment | string | AzureCloud | For cloud environments other than the US public cloud, the environment name (as defined by Azure Python SDK, eg, C(AzureChinaCloud), C(AzureUSGovernment)), or a metadata discovery endpoint URL (required for Azure Stack). Can also be set via credential file profile or the C(AZURE_CLOUD_ENVIRONMENT) environment variable. | |
| created_nsg | bool | true | Whether network security group created and attached to network interface or not. | |
| custom_data | string | Data made available to the VM and used by C(cloud-init). | ||
| Only used on Linux images with C(cloud-init) enabled. | ||||
| Consult U(https://docs.microsoft.com/en-us/azure/virtual-machines/linux/using-cloud-init#cloud-init-overview) for cloud-init ready images. | ||||
| To enable cloud-init on a Linux image, follow U(https://docs.microsoft.com/en-us/azure/virtual-machines/linux/cloudinit-prepare-custom-image). | ||||
| data_disks | list | Describes list of data disks. | ||
| Use M(azure.azcollection.azure_rm_manageddisk) to manage the specific disk. | ||||
| disable_instance_discovery | bool | false | Determines whether or not instance discovery is performed when attempting to authenticate. Setting this to true will completely disable both instance discovery and authority validation. This functionality is intended for use in scenarios where the metadata endpoint cannot be reached such as in private clouds or Azure Stack. The process of instance discovery entails retrieving authority metadata from https://login.microsoft.com/ to validate the authority. By setting this to True, the validation of the authority is disabled. As a result, it is crucial to ensure that the configured authority host is valid and trustworthy. | |
| Set via credential file profile or the C(AZURE_DISABLE_INSTANCE_DISCOVERY) environment variable. | ||||
| ephemeral_os_disk | bool | Parameters of ephemeral disk settings that can be specified for operating system disk. | ||
| Ephemeral OS disk is only supported for VMS Instances using Managed Disk. | ||||
| If the VM gets deleted, the ephemeral OS disk will be deleted and cannot be detached. | ||||
| eviction_policy | string | Specifies the eviction policy for the Azure Spot virtual machine. | ||
| Requires priority to be set to Spot. | ||||
| force | bool | false | Use more force during stop of VM | |
| Set to C(true) with I(started=false) to stop the VM forcefully (hard poweroff – skip_shutdown) | ||||
| Set to C(false) to power off gracefully | ||||
| generalized | bool | false | Whether the VM is generalized or not. | |
| Set to C(true) with I(state=present) to generalize the VM. | ||||
| Generalizing a VM is irreversible. | ||||
| image | raw | 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. | ||||
| For share gallery image, a dict with the keys I(shared_gallery_image_id). Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call. | ||||
| Required when creating. | ||||
| license_type | string | On-premise license for the image or disk. | ||
| Only used for images that contain the Windows Server operating system. | ||||
| To remove all license type settings, set to the string C(None). | ||||
| linux_config | dict | Specifies the Linux operating system settings on the virtual machine. | ||
| location | string | Valid Azure location for the VM. Defaults to location of the resource group. | ||
| log_mode | string | Parent argument. | ||
| log_path | string | Parent argument. | ||
| managed_disk_type | string | Managed OS disk type. | ||
| Create OS disk with managed disk if defined. | ||||
| Defaults to C(Standard_LRS) when no disk options are specified. | ||||
| Unmanaged disks were retired by Azure on March 31, 2026. | ||||
| See U(https://learn.microsoft.com/azure/virtual-machines/unmanaged-disks-deprecation). | ||||
| max_price | float | -1 | Specifies the maximum price you are willing to pay for a Azure Spot VM/VMSS. | |
| This price is in US Dollars. | ||||
| C(-1) indicates default price to be up-to on-demand. | ||||
| Requires priority to be set to Spot. | ||||
| name | string | yes | Name of the VM. | |
| network_interface_names | list | Network interface names to add to the VM. | ||
| Can be a string of name or resource ID of the network interface. | ||||
| Can be a dict containing I(resource_group) and I(name) of the network interface. | ||||
| If a network interface name is not provided when the VM is created, a default network interface and public IP address will be created. | ||||
| If the VM gets deleted, the default network interface and default public IP address will be deleted as well. | ||||
| To create a new network interface, at least one Virtual Network with one Subnet must exist. | ||||
| oidc_token | string | Direct OpenID Connect (OIDC) token (JWT) used for workload identity authentication. | ||
| This token is exchanged with Azure AD using OIDC federated identity. | ||||
| Useful in CI systems (for example GitHub Actions, Azure DevOps) where an OIDC token is provided directly by the platform. | ||||
| Can also be set via the C(AZURE_FEDERATED_TOKEN) environment variable. | ||||
| oidc_token_file_path | string | Path to a file containing an OpenID Connect (OIDC) token (JWT) used for workload identity authentication. | ||
| The file must contain only raw token. | ||||
| This method is commonly used in platforms that materialize OIDC tokens as files | ||||
| Can also be set via the C(AZURE_FEDERATED_TOKEN_FILE) environment variable. | ||||
| open_ports | list | List of ports to open in the security group for the VM, when a security group and network interface are created with a VM. | ||
| For Linux hosts, defaults to allowing inbound TCP connections to port 22. | ||||
| For Windows hosts, defaults to opening ports 3389 and 5986. | ||||
| os_disk_caching | string | Type of OS disk caching. | ||
| os_disk_delete_option | string | Specifies the delete behavior for the VM’s OS disk when VM is deleted. | ||
| Azure default to Detach if no specified. | ||||
| When set to C(Delete), the OS disk will be removed automatically during VM deletion. | ||||
| When set to C(Detach), the OS disk will be preserved. | ||||
| os_disk_encryption_set | string | ID of disk encryption set for OS disk. | ||
| os_disk_name | string | OS disk name. | ||
| os_disk_size_gb | int | Size of OS disk in GB. | ||
| os_type | string | Linux | Base type of operating system. | |
| password | string | Active Directory user password. Use when authenticating with an Active Directory user rather than service principal. | ||
| plan | dict | Third-party billing plan for the VM. | ||
| priority | string | Priority of the VM. | ||
| C(None) is the equivalent of Regular VM. | ||||
| profile | string | Security profile found in ~/.azure/credentials file. | ||
| proximity_placement_group | dict | The name or ID of the proximity placement group to be associated with. | ||
| public_ip_allocation_method | string | Static | Allocation method for the public IP of the VM. | |
| Used only if a network interface is not specified. | ||||
| When set to C(Dynamic), the public IP address may change any time the VM is rebooted or power cycled. | ||||
| The C(Disabled) choice was added in Ansible 2.6. | ||||
| remove_on_absent | list | [all] | Associated resources to remove when removing a VM using I(state=absent). | |
| To remove all resources related to the VM being removed, including auto-created resources, set to C(all). | ||||
| To remove only resources that were automatically created while provisioning the VM being removed, set to C(all_autocreated). | ||||
| To remove only specific resources, set to C(network_interfaces), C(virtual_storage) or C(public_ips). | ||||
| Any other input will be ignored. | ||||
| resource_group | string | yes | Name of the resource group containing the VM. | |
| restarted | bool | false | Set to C(true) with I(state=present) to restart a running VM. | |
| secret | string | Azure client secret. Use when authenticating with a Service Principal. | ||
| security_profile | dict | Specifies the Security related profile settings for the virtual machine. | ||
| short_hostname | string | Name assigned internally to the host. On a Linux VM this is the name returned by the C(hostname) command. | ||
| When creating a VM, short_hostname defaults to I(name). | ||||
| specialized_image | bool | false | Set to C(true) when the source image referenced by I(image) has an C(osState) of C(Specialized). For example a Shared Image Gallery (Azure Compute Gallery) version, managed image, or attached OS disk that already has accounts, hostname and OS-level settings baked in. | |
| When C(true), the module omits the C(osProfile) block from the Virtual Machine create request. Azure rejects specialized sources with C(Parameter OSProfile is not allowed with a specialized image) when C(osProfile) is present. | ||||
| When C(true), these options are ignored during VM creation - I(admin_username), I(admin_password), I(ssh_public_keys), I(ssh_password_enabled), I(custom_data), I(short_hostname), I(windows_config) and I(linux_config). | ||||
| Distinct from I(generalized), which requests a power-state transition (sysprep/deprovision) on an existing VM and does not describe the source image. | ||||
| ssh_password_enabled | bool | true | Whether to enable or disable SSH passwords. | |
| When I(os_type=Linux), set to C(false) to disable SSH password authentication and require use of SSH keys. | ||||
| ssh_public_keys | list | For I(os_type=Linux) provide a list of SSH keys. | ||
| Accepts a list of dicts where each dictionary contains two keys, I(path) and I(key_data). | ||||
| Set I(path) to the default location of the authorized_keys files. For example, I(path=/home/ | ||||
| Set I(key_data) to the actual value of the public key. | ||||
| started | bool | Whether the VM is started or stopped. | ||
| Set to C(true) with I(state=present) to start the VM. | ||||
| Set to C(false) to stop the VM. | ||||
| state | string | present | State of the VM. | |
| Set to C(present) to create a VM with the configuration specified by other options, or to update the configuration of an existing VM. | ||||
| Set to C(absent) to remove a VM. | ||||
| Does not affect power state. Use I(started)/I(allocated)/I(restarted) parameters to change the power state of a VM. | ||||
| storage_account_name | string | (Deprecated) Name of a storage account that supports creation of VHD blobs. | ||
| If not specified for a new VM, a new storage account named | ||||
| Unmanaged disks were retired by Azure on March 31, 2026. Use I(managed_disk_type) instead. | ||||
| See U(https://learn.microsoft.com/azure/virtual-machines/unmanaged-disks-deprecation). | ||||
| This option will be removed in version 4.0.0. | ||||
| storage_blob_name | string | (Deprecated) Name of the storage blob used to hold the OS disk image of the VM. | ||
| Must end with ‘.vhd’. | ||||
| If not specified, defaults to the VM name + ‘.vhd’. | ||||
| Unmanaged disks were retired by Azure on March 31, 2026. Use I(managed_disk_type) instead. | ||||
| This option will be removed in version 4.0.0. | ||||
| See U(https://learn.microsoft.com/azure/virtual-machines/unmanaged-disks-deprecation). | ||||
| storage_container_name | string | vhds | (Deprecated) Name of the container to use within the storage account to store VHD blobs. | |
| If not specified, a default container will be created. | ||||
| Unmanaged disks were retired by Azure on March 31, 2026. Use I(managed_disk_type) instead. | ||||
| This option will be removed in version 4.0.0. | ||||
| See U(https://learn.microsoft.com/azure/virtual-machines/unmanaged-disks-deprecation). | ||||
| subnet_name | string | Subnet for the VM. | ||
| Defaults to the first subnet found in the virtual network or the subnet of the I(network_interface_name), if provided. | ||||
| If the subnet is in another resource group, specify the resource group with I(virtual_network_resource_group). | ||||
| subscription_id | string | Your Azure subscription Id. | ||
| swap_os_disk | dict | The swap OS disk parameters. | ||
| tags | dict | Dictionary of string:string pairs to assign as metadata to the object. | ||
| Metadata tags on the object will be updated with any provided values. | ||||
| To remove tags set append_tags option to false. | ||||
| Currently, Azure DNS zones and Traffic Manager services also don’t allow the use of spaces in the tag. | ||||
| Azure Front Door doesn’t support the use of | ||||
| Azure Automation and Azure CDN only support 15 tags on resources. | ||||
| tenant | string | Azure tenant ID. Use when authenticating with a Service Principal. | ||
| thumbprint | string | The thumbprint of the private key specified in I(x509_certificate_path). | ||
| Use when authenticating with a Service Principal. | ||||
| Required if I(x509_certificate_path) is defined. | ||||
| user_data | string | UserData for the VM, which must be base-64 encoded. | ||
| Customer should notpass any secrets in here. Minimum api-version ‘2021-03-01’. | ||||
| virtual_network_name | string | The virtual network to use when creating a VM. | ||
| If not specified, a new network interface will be created and assigned to the first virtual network found in the resource group. | ||||
| Use with I(virtual_network_resource_group) to place the virtual network in another resource group. | ||||
| virtual_network_resource_group | string | The resource group to use when creating a VM with another resource group’s virtual network. | ||
| vm_identity | dict | Identity for the VM. | ||
| vm_size | string | A valid Azure VM size value. For example, C(Standard_D4). | ||
| Choices vary depending on the subscription and location. Check your subscription for available choices. | ||||
| Required when creating a VM. | ||||
| windows_config | dict | Specifies Windows operating system settings on the virtual machine. | ||
| winrm | list | List of Windows Remote Management configurations of the VM. | ||
| x509_certificate_path | string | Path to the X509 certificate used to create the service principal in PEM format. | ||
| The certificate must be appended to the private key. | ||||
| Use when authenticating with a Service Principal. | ||||
| zones | list | A list of Availability Zones for your VM. | ||
| A maximum of one zone can be configured. |
Example
yaml
- name: Create VM with defaults
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm10
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image:
offer: CentOS
publisher: OpenLogic
sku: '7.1'
version: latest
- name: Create an availability set for managed disk vm
azure.azcollection.azure_rm_availabilityset:
name: avs-managed-disk
resource_group: myResourceGroup
platform_update_domain_count: 5
platform_fault_domain_count: 2
sku: Aligned
- name: Create a VM with managed disk
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: vm-managed-disk
admin_username: "{{ username }}"
availability_set: avs-managed-disk
managed_disk_type: Standard_LRS
image:
offer: 0001-com-ubuntu-server-focal
publisher: canonical
sku: 20_04-lts-gen2
version: latest
vm_size: Standard_D4
- name: Create a VM with existing storage account and NIC
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm002
vm_size: Standard_D4
storage_account: testaccount001
admin_username: "{{ username }}"
ssh_public_keys:
- path: /home/adminUser/.ssh/authorized_keys
key_data: < insert your ssh public key here... >
network_interfaces: testvm001
image:
offer: CentOS
publisher: OpenLogic
sku: '7.1'
version: latest
- name: Create a VM with OS and multiple data managed disks
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_D4
managed_disk_type: Standard_LRS
admin_username: "{{ username }}"
ssh_public_keys:
- path: /home/adminUser/.ssh/authorized_keys
key_data: < insert your ssh public key here... >
image:
offer: 0001-com-ubuntu-server-focal
publisher: canonical
sku: 20_04-lts-gen2
version: latest
data_disks:
- lun: 0
managed_disk_id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myDisk"
- lun: 1
name: newdisk
disk_size_gb: 128
managed_disk_type: Premium_LRS
- name: Create a VM with OS and multiple data storage accounts
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: "{{ username }}"
ssh_password_enabled: false
ssh_public_keys:
- path: /home/adminUser/.ssh/authorized_keys
key_data: < insert your ssh public key here... >
network_interfaces: testvm001
storage_container: osdisk
storage_blob: osdisk.vhd
boot_diagnostics:
enabled: true
type: managed
image:
offer: 0001-com-ubuntu-server-focal
publisher: canonical
sku: 20_04-lts-gen2
version: latest
data_disks:
- lun: 0
disk_size_gb: 64
storage_container_name: datadisk1
storage_blob_name: datadisk1.vhd
- lun: 1
disk_size_gb: 128
storage_container_name: datadisk2
storage_blob_name: datadisk2.vhd
- name: Create a VM with a custom image
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image: customimage001
- name: Create a VM with a custom image from a particular resource group
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image:
name: customimage001
resource_group: myResourceGroup
- name: Create a VM with an image id
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image:
id: '{{image_id}}'
- name: Create a VM from a custom image and override data disk types
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: "{{ username }}"
admin_password: "{{ password }}"
managed_disk_type: StandardSSD_LRS
image:
id: '{{ image_id }}'
data_disks:
- lun: 0
create_option: FromImage
managed_disk_type: StandardSSD_LRS
- lun: 1
create_option: FromImage
managed_disk_type: StandardSSD_LRS
- name: Create a VM with spcified OS disk size
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: big-os-disk
admin_username: "{{ username }}"
admin_password: "{{ password }}"
os_disk_size_gb: 512
image:
offer: CentOS
publisher: OpenLogic
sku: '7.1'
version: latest
- name: Create a VM with OS and Plan, accepting the terms
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: f5-nva
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image:
publisher: f5-networks
offer: f5-big-ip-best
sku: f5-bigip-virtual-edition-200m-best-hourly
version: latest
plan:
name: f5-bigip-virtual-edition-200m-best-hourly
product: f5-big-ip-best
publisher: f5-networks
- name: Create a VM with Spot Instance
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm10
vm_size: Standard_D4
priority: Spot
eviction_policy: Deallocate
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image:
offer: CentOS
publisher: OpenLogic
sku: '7.1'
version: latest
- name: Update VM to swap OS disk
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "vmforimage{{ rpfx }}"
admin_username: testuser
ssh_password_enabled: false
managed_disk_type: Premium_LRS
ssh_public_keys:
- path: /home/testuser/.ssh/authorized_keys
key_data: "ssh-rsa *******************@qq.com"
vm_size: Standard_D4s_v3
swap_os_disk:
os_disk_name: "{{ os_disk_name }}"
os_disk_resource_group: "{{ os_disk_resource_group }}"
image:
offer: 0001-com-ubuntu-server-focal
publisher: Canonical
sku: 20_04-lts
version: latest
- name: Create VM with cummunity gallery image ID
azure.azcollection.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.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm002
started: false
- name: Deallocate
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm002
allocated: false
- name: Power On
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm002
- name: Restart
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm002
restarted: true
- name: Create a VM with an Availability Zone
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm001
vm_size: Standard_DS1_v2
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image: customimage001
zones: [1]
- name: Create a VM with security profile
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
vm_size: Standard_D4s_v3
managed_disk_type: Standard_LRS
admin_username: "{{ username }}"
admin_password: "{{ password }}"
security_profile:
uefi_settings:
secure_boot_enabled: true
v_tpm_enabled: true
encryption_at_host: true
security_type: TrustedLaunch
ssh_public_keys:
- path: /home/azureuser/.ssh/authorized_keys
key_data: "ssh-rsa *****"
image:
offer: 0001-com-ubuntu-server-jammy
publisher: Canonical
sku: 22_04-lts-gen2
version: latest
- name: Create a VM and enable deleteOption on OS disk and data disk
azure.azcollection.azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
vm_size: Standard_D4s_v3
managed_disk_type: Standard_LRS
admin_username: "{{ username }}"
admin_password: "{{ password }}"
image:
offer: 0001-com-ubuntu-server-jammy
publisher: Canonical
sku: 22_04-lts-gen2
version: latest
os_disk_delete_option: Delete
data_disks:
- lun: 0
disk_size_gb: 64
storage_container_name: datadisk1
storage_blob_name: datadisk1.vhd
delete_option: Delete
- name: Remove a VM and all resources that were autocreated
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm002
remove_on_absent: all_autocreated
state: absent
- name: Create a VM from a Specialized Shared Image Gallery version
azure.azcollection.azure_rm_virtualmachine:
resource_group: myResourceGroup
name: testvm-specialized
vm_size: Standard_B1s
specialized_image: true
os_type: Linux
managed_disk_type: StandardSSD_LRS
network_interfaces: testvm-specialized-nic
image:
id: >-
/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGallery/images/myImage/versions/1.0.0