azure / azure.azcollection / 0.3.0 / module / azure_rm_virtualmachine Manage Azure virtual machines | "added in version" 2.1 of azure.azcollection" Authors: Chris Houseknecht (@chouseknecht), Matt Davis (@nitzmahone), Christopher Perrin (@cperrin88), James E. King III (@jeking3) preview | supported by communityazure.azcollection.azure_rm_virtualmachine (0.3.0) — module
Install with ansible-galaxy collection install azure.azcollection:==0.3.0
collections: - name: azure.azcollection version: 0.3.0
Manage and configure virtual machines (VMs) and associated resources on Azure.
Requires a resource group containing at least one virtual network with at least one subnet.
Supports images from the Azure Marketplace, which can be discovered with M(azure_rm_virtualmachineimage_info).
Supports custom images since Ansible 2.5.
To use I(custom_data) on a Linux image, the image must have cloud-init enabled. If cloud-init is not enabled, I(custom_data) is ignored.
- name: Create VM with defaults azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm10 admin_username: chouseknecht admin_password: <your password here> image: offer: CentOS publisher: OpenLogic sku: '7.1' version: latest
- name: Create an availability set for managed disk vm 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_rm_virtualmachine: resource_group: myResourceGroup name: vm-managed-disk admin_username: adminUser availability_set: avs-managed-disk managed_disk_type: Standard_LRS image: offer: CoreOS publisher: CoreOS sku: Stable version: latest vm_size: Standard_D4
- name: Create a VM with existing storage account and NIC azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm002 vm_size: Standard_D4 storage_account: testaccount001 admin_username: adminUser ssh_public_keys: - path: /home/adminUser/.ssh/authorized_keys key_data: < insert yor 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_rm_virtualmachine: resource_group: myResourceGroup name: testvm001 vm_size: Standard_D4 managed_disk_type: Standard_LRS admin_username: adminUser ssh_public_keys: - path: /home/adminUser/.ssh/authorized_keys key_data: < insert yor ssh public key here... > image: offer: CoreOS publisher: CoreOS sku: Stable version: latest data_disks: - lun: 0 managed_disk_id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myDisk" - lun: 1 disk_size_gb: 128 managed_disk_type: Premium_LRS
- name: Create a VM with OS and multiple data storage accounts azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm001 vm_size: Standard_DS1_v2 admin_username: adminUser ssh_password_enabled: false ssh_public_keys: - path: /home/adminUser/.ssh/authorized_keys key_data: < insert yor ssh public key here... > network_interfaces: testvm001 storage_container: osdisk storage_blob: osdisk.vhd boot_diagnostics: enabled: yes image: offer: CoreOS publisher: CoreOS sku: Stable 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_rm_virtualmachine: resource_group: myResourceGroup name: testvm001 vm_size: Standard_DS1_v2 admin_username: adminUser admin_password: password01 image: customimage001
- name: Create a VM with a custom image from a particular resource group azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm001 vm_size: Standard_DS1_v2 admin_username: adminUser admin_password: password01 image: name: customimage001 resource_group: myResourceGroup
- name: Create a VM with an image id azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm001 vm_size: Standard_DS1_v2 admin_username: adminUser admin_password: password01 image: id: '{{image_id}}'
- name: Create VM with spcified OS disk size azure_rm_virtualmachine: resource_group: myResourceGroup name: big-os-disk admin_username: chouseknecht admin_password: <your password here> os_disk_size_gb: 512 image: offer: CentOS publisher: OpenLogic sku: '7.1' version: latest
- name: Create VM with OS and Plan, accepting the terms azure_rm_virtualmachine: resource_group: myResourceGroup name: f5-nva admin_username: chouseknecht admin_password: <your password here> 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: Power Off azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm002 started: no
- name: Deallocate azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm002 allocated: no
- name: Power On azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm002
- name: Restart azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm002 restarted: yes
- name: Create a VM with an Availability Zone azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm001 vm_size: Standard_DS1_v2 admin_username: adminUser admin_password: password01 image: customimage001 zones: [1]
- name: Remove a VM and all resources that were autocreated azure_rm_virtualmachine: resource_group: myResourceGroup name: testvm002 remove_on_absent: all_autocreated state: absent
name: description: - Name of the VM. required: true plan: description: - Third-party billing plan for the VM. suboptions: name: description: - Billing plan name. required: true product: description: - Product name. required: true promotion_code: description: - Optional promotion code. publisher: description: - Publisher offering the plan. required: true type: dict version_added: '2.5' version_added_collection: azure.azcollection tags: description: - 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. type: dict image: 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 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: true state: choices: - absent - present default: present description: - 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. winrm: description: - List of Windows Remote Management configurations of the VM. suboptions: certificate_store: description: - The certificate store on the VM to which the certificate should be added. - The specified certificate store is implicitly in the LocalMachine account. certificate_url: description: - The URL of a certificate that has been uploaded to Key Vault as a secret. protocol: choices: - http - https description: - The protocol of the winrm listener. required: true source_vault: description: - The relative URL of the Key Vault containing the certificate. version_added: '2.8' version_added_collection: azure.azcollection zones: description: - A list of Availability Zones for your VM. type: list version_added: '2.8' version_added_collection: azure.azcollection secret: description: - Azure client secret. Use when authenticating with a Service Principal. type: str tenant: description: - Azure tenant ID. Use when authenticating with a Service Principal. type: str ad_user: description: - Active Directory username. Use when authenticating with an Active Directory user rather than service principal. type: str os_type: choices: - Windows - Linux default: Linux description: - Base type of operating system. profile: description: - Security profile found in ~/.azure/credentials file. type: str started: default: true description: - Whether the VM is started or stopped. - Set to (true) with I(state=present) to start the VM. - Set to C(false) to stop the VM. type: bool vm_size: description: - 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. location: description: - Valid Azure location for the VM. Defaults to location of the resource group. password: description: - Active Directory user password. Use when authenticating with an Active Directory user rather than service principal. type: str allocated: default: true description: - Whether the VM is allocated or deallocated, only useful with I(state=present). type: bool client_id: description: - Azure client ID. Use when authenticating with a Service Principal. type: str restarted: description: - Set to C(true) with I(state=present) to restart a running VM. type: bool data_disks: description: - Describes list of data disks. - Use M(azure_rm_mangeddisk) to manage the specific disk. suboptions: caching: choices: - ReadOnly - ReadWrite default: ReadOnly description: - Type of data disk caching. version_added: '2.4' version_added_collection: azure.azcollection disk_size_gb: description: - The initial disk size in GB for blank data disks. - This value cannot be larger than C(1023) GB. - Size can be changed only when the virtual machine is deallocated. - Not sure when I(managed_disk_id) defined. version_added: '2.4' version_added_collection: azure.azcollection lun: description: - The logical unit number for data disk. - This value is used to identify data disks within the VM and therefore must be unique for each data disk attached to a VM. required: true version_added: '2.4' version_added_collection: azure.azcollection managed_disk_type: choices: - Standard_LRS - StandardSSD_LRS - Premium_LRS description: - Managed data disk type. - Only used when OS disk created with managed disk. version_added: '2.4' version_added_collection: azure.azcollection storage_account_name: description: - Name of an existing storage account that supports creation of VHD blobs. - If not specified for a new VM, a new storage account started with I(name) will be created using storage type C(Standard_LRS). - Only used when OS disk created with virtual hard disk (VHD). - Used when I(managed_disk_type) not defined. - Cannot be updated unless I(lun) updated. version_added: '2.4' version_added_collection: azure.azcollection storage_blob_name: description: - Name of the storage blob used to hold the OS disk image of the VM. - Must end with '.vhd'. - Default to the I(name) + timestamp + I(lun) + '.vhd'. - Only used when OS disk created with virtual hard disk (VHD). - Used when I(managed_disk_type) not defined. - Cannot be updated unless I(lun) updated. version_added: '2.4' version_added_collection: azure.azcollection storage_container_name: default: vhds description: - Name of the container to use within the storage account to store VHD blobs. - If no name is specified a default container named 'vhds' will created. - Only used when OS disk created with virtual hard disk (VHD). - Used when I(managed_disk_type) not defined. - Cannot be updated unless I(lun) updated. version_added: '2.4' version_added_collection: azure.azcollection version_added: '2.4' version_added_collection: azure.azcollection open_ports: description: - 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. api_profile: default: latest description: - 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. type: str version_added: '2.5' version_added_collection: azure.azcollection append_tags: default: true description: - 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. type: bool auth_source: choices: - auto - cli - credential_file - env - msi description: - Controls the source of the credentials to use for authentication. - If not specified, ANSIBLE_AZURE_AUTH_SOURCE environment variable will be used and default to C(auto) if variable is not defined. - C(auto) will follow the default precedence of module parameters -> environment variables -> default profile in credential file C(~/.azure/credentials). - When set to C(cli), the credentials will be sources from the default Azure CLI profile. - Can also be set via the C(ANSIBLE_AZURE_AUTH_SOURCE) environment variable. - 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. type: str version_added: '2.5' version_added_collection: azure.azcollection custom_data: description: - 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). version_added: '2.5' version_added_collection: azure.azcollection generalized: description: - Whether the VM is generalized or not. - Set to C(true) with I(state=present) to generalize the VM. - Generalizing a VM is irreversible. type: bool version_added: '2.8' version_added_collection: azure.azcollection subnet_name: aliases: - subnet description: - 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). vm_identity: choices: - SystemAssigned description: - Identity for the VM. version_added: '2.8' version_added_collection: azure.azcollection accept_terms: default: false description: - 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. type: bool version_added: '2.7' version_added_collection: azure.azcollection license_type: choices: - Windows_Server - Windows_Client description: - 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). version_added: '2.8' version_added_collection: azure.azcollection os_disk_name: description: - OS disk name. version_added: '2.8' version_added_collection: azure.azcollection admin_password: description: - 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: description: - Admin username used to access the VM after it is created. - Required when creating a VM. resource_group: description: - Name of the resource group containing the VM. required: true short_hostname: description: - 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). os_disk_caching: aliases: - disk_caching choices: - ReadOnly - ReadWrite description: - Type of OS disk caching. os_disk_size_gb: description: - Type of OS disk size in GB. version_added: '2.7' version_added_collection: azure.azcollection ssh_public_keys: description: - 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/<admin username>/.ssh/authorized_keys). - Set I(key_data) to the actual value of the public key. subscription_id: description: - Your Azure subscription Id. type: str availability_set: description: - 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. version_added: '2.5' version_added_collection: azure.azcollection boot_diagnostics: description: - Manage boot diagnostics settings for a VM. - Boot diagnostics includes a serial console and remote console screenshots. suboptions: enabled: description: - Flag indicating if boot diagnostics are enabled. required: true type: bool storage_account: description: - The name of an existing storage account to use for boot diagnostics. - If not specified, uses I(storage_account_name) defined one level up. - If storage account is not specified anywhere, and C(enabled) is C(true), a default storage account is created for boot diagnostics data. required: false version_added: '2.9' version_added_collection: azure.azcollection remove_on_absent: default: - all description: - 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. type: list cloud_environment: default: AzureCloud description: - 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. type: str version_added: '2.4' version_added_collection: azure.azcollection ephemeral_os_disk: default: false description: - 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. type: bool managed_disk_type: choices: - Standard_LRS - StandardSSD_LRS - Premium_LRS description: - Managed OS disk type. - Create OS disk with managed disk if defined. - If not defined, the OS disk will be created with virtual hard disk (VHD). version_added: '2.4' version_added_collection: azure.azcollection storage_blob_name: aliases: - storage_blob description: - 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'. adfs_authority_url: description: - Azure AD authority url. Use when authenticating with Username/password, and has your own ADFS authority. type: str version_added: '2.6' version_added_collection: azure.azcollection cert_validation_mode: choices: - ignore - validate description: - 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. type: str version_added: '2.5' version_added_collection: azure.azcollection ssh_password_enabled: default: true description: - 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. type: bool storage_account_name: aliases: - storage_account description: - Name of a storage account that supports creation of VHD blobs. - If not specified for a new VM, a new storage account named <vm name>01 will be created using storage type C(Standard_LRS). virtual_network_name: aliases: - virtual_network description: - 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. storage_container_name: aliases: - storage_container default: vhds description: - Name of the container to use within the storage account to store VHD blobs. - If not specified, a default container will be created. network_interface_names: aliases: - network_interfaces description: - 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 will be created. - To create a new network interface, at least one Virtual Network with one Subnet must exist. type: list public_ip_allocation_method: aliases: - public_ip_allocation choices: - Dynamic - Static - Disabled default: Static description: - 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. virtual_network_resource_group: description: - The resource group to use when creating a VM with another resource group's virtual network. version_added: '2.4' version_added_collection: azure.azcollection
azure_vm: description: - Facts about the current state of the object. Note that facts are not part of the registered output but available directly. returned: always sample: properties: availabilitySet: id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Compute/availabilitySets/MYAVAILABILITYSET hardwareProfile: vmSize: Standard_D1 instanceView: disks: - name: testvm10.vhd statuses: - code: ProvisioningState/succeeded displayStatus: Provisioning succeeded level: Info time: '2016-03-30T07:11:16.187272Z' statuses: - code: ProvisioningState/succeeded displayStatus: Provisioning succeeded level: Info time: '2016-03-30T20:33:38.946916Z' - code: PowerState/running displayStatus: VM running level: Info vmAgent: extensionHandlers: [] statuses: - code: ProvisioningState/succeeded displayStatus: Ready level: Info message: GuestAgent is running and accepting new configurations. time: '2016-03-30T20:31:16.000Z' vmAgentVersion: WALinuxAgent-2.0.16 networkProfile: networkInterfaces: - id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/networkInterfaces/testvm10_NIC01 name: testvm10_NIC01 properties: dnsSettings: appliedDnsServers: [] dnsServers: [] enableIPForwarding: false ipConfigurations: - etag: W/"041c8c2a-d5dd-4cd7-8465-9125cfbe2cf8" id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/networkInterfaces/testvm10_NIC01/ipConfigurations/default name: default properties: privateIPAddress: 10.10.0.5 privateIPAllocationMethod: Dynamic provisioningState: Succeeded publicIPAddress: id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/testvm10_PIP01 name: testvm10_PIP01 properties: idleTimeoutInMinutes: 4 ipAddress: 13.92.246.197 ipConfiguration: id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Network/networkInterfaces/testvm10_NIC01/ipConfigurations/default provisioningState: Succeeded publicIPAllocationMethod: Static resourceGuid: 3447d987-ca0d-4eca-818b-5dddc0625b42 macAddress: 00-0D-3A-12-AA-14 primary: true provisioningState: Succeeded resourceGuid: 10979e12-ccf9-42ee-9f6d-ff2cc63b3844 virtualMachine: id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroup/myResourceGroup/providers/Microsoft.Compute/virtualMachines/testvm10 osProfile: adminUsername: chouseknecht computerName: test10 linuxConfiguration: disablePasswordAuthentication: false secrets: [] provisioningState: Succeeded storageProfile: dataDisks: - caching: ReadWrite createOption: empty diskSizeGB: 64 lun: 0 name: datadisk1.vhd vhd: uri: https://testvm10sa1.blob.core.windows.net/datadisk/datadisk1.vhd imageReference: offer: CentOS publisher: OpenLogic sku: '7.1' version: 7.1.20160308 osDisk: caching: ReadOnly createOption: fromImage name: testvm10.vhd osType: Linux vhd: uri: https://testvm10sa1.blob.core.windows.net/vhds/testvm10.vhd type: Microsoft.Compute/virtualMachines type: dict deleted_network_interfaces: description: - List of deleted NICs. returned: on delete sample: - testvm1001 type: list deleted_public_ips: description: - List of deleted public IP address names. returned: on delete sample: - testvm1001 type: list deleted_vhd_uris: description: - List of deleted Virtual Hard Disk URIs. returned: on delete sample: - https://testvm104519.blob.core.windows.net/vhds/testvm10.vhd type: list powerstate: description: - Indicates if the state is C(running), C(stopped), C(deallocated), C(generalized). returned: always sample: running type: str