@ -46,7 +46,6 @@ options:
state .
state .
- State ' absent ' will remove the virtual machine .
- State ' absent ' will remove the virtual machine .
default : present
default : present
required : false
choices :
choices :
- absent
- absent
- present
- present
@ -54,28 +53,21 @@ options:
description :
description :
- Use with state ' present ' to start the machine . Set to false to have the machine be ' stopped ' .
- Use with state ' present ' to start the machine . Set to false to have the machine be ' stopped ' .
default : true
default : true
required : false
allocated :
allocated :
description :
description :
- Toggle that controls if the machine is allocated / deallocated , only useful with state = ' present ' .
- Toggle that controls if the machine is allocated / deallocated , only useful with state = ' present ' .
default : True
default : True
required : false
restarted :
restarted :
description :
description :
- Use with state ' present ' to restart a running VM .
- Use with state ' present ' to restart a running VM .
default : false
default : false
required : false
location :
location :
description :
description :
- Valid Azure location . Defaults to location of the resource group .
- Valid Azure location . Defaults to location of the resource group .
default : null
required : false
short_hostname :
short_hostname :
description :
description :
- Name assigned internally to the host . On a linux VM this is the name returned by the ` hostname ` command .
- Name assigned internally to the host . On a linux VM this is the name returned by the ` hostname ` command .
When creating a virtual machine , short_hostname defaults to name .
When creating a virtual machine , short_hostname defaults to name .
default : null
required : false
vm_size :
vm_size :
description :
description :
- A valid Azure VM size value . For example , ' Standard_D4 ' . The list of choices varies depending on the
- A valid Azure VM size value . For example , ' Standard_D4 ' . The list of choices varies depending on the
@ -84,28 +76,21 @@ options:
admin_username :
admin_username :
description :
description :
- Admin username used to access the host after it is created . Required when creating a VM .
- Admin username used to access the host after it is created . Required when creating a VM .
default : null
required : false
admin_password :
admin_password :
description :
description :
- Password for the admin username . Not required if the os_type is Linux and SSH password authentication
- Password for the admin username . Not required if the os_type is Linux and SSH password authentication
is disabled by setting ssh_password_enabled to false .
is disabled by setting ssh_password_enabled to false .
default : null
required : false
ssh_password_enabled :
ssh_password_enabled :
description :
description :
- When the os_type is Linux , setting ssh_password_enabled to false will disable SSH password authentication
- When the os_type is Linux , setting ssh_password_enabled to false will disable SSH password authentication
and require use of SSH keys .
and require use of SSH keys .
default : true
default : true
required : false
ssh_public_keys :
ssh_public_keys :
description :
description :
- " For os_type Linux provide a list of SSH keys. Each item in the list should be a dictionary where the
- " For os_type Linux provide a list of SSH keys. Each item in the list should be a dictionary where the
dictionary contains two keys : path and key_data . Set the path to the default location of the
dictionary contains two keys : path and key_data . Set the path to the default location of the
authorized_keys files . On an Enterprise Linux host , for example , the path will be
authorized_keys files . On an Enterprise Linux host , for example , the path will be
/ home / < admin username > / . ssh / authorized_keys . Set key_data to the actual value of the public key . "
/ home / < admin username > / . ssh / authorized_keys . Set key_data to the actual value of the public key . "
default : null
required : false
image :
image :
description :
description :
- " A dictionary describing the Marketplace image used to build the VM. Will contain keys: publisher,
- " A dictionary describing the Marketplace image used to build the VM. Will contain keys: publisher,
@ -116,22 +101,17 @@ options:
description :
description :
- Name of an existing storage account that supports creation of VHD blobs . If not specified for a new VM ,
- Name of an existing 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 ' Standard_LRS ' .
a new storage account named < vm name > 01 will be created using storage type ' Standard_LRS ' .
default : null
required : false
storage_container_name :
storage_container_name :
description :
description :
- Name of the container to use within the storage account to store VHD blobs . If no name is specified a
- Name of the container to use within the storage account to store VHD blobs . If no name is specified a
default container will created .
default container will created .
default : vhds
default : vhds
required : false
storage_blob_name :
storage_blob_name :
description :
description :
- Name fo the storage blob used to hold the VM ' s OS disk image. If no name is provided, defaults to
- Name fo the storage blob used to hold the VM ' s OS disk image. If no name is provided, defaults to
the VM name + ' .vhd ' . If you provide a name , it must end with ' .vhd '
the VM name + ' .vhd ' . If you provide a name , it must end with ' .vhd '
aliases :
aliases :
- storage_blob
- storage_blob
default : null
required : false
os_disk_caching :
os_disk_caching :
description :
description :
- Type of OS disk caching .
- Type of OS disk caching .
@ -141,7 +121,6 @@ options:
default : ReadOnly
default : ReadOnly
aliases :
aliases :
- disk_caching
- disk_caching
required : false
os_type :
os_type :
description :
description :
- Base type of operating system .
- Base type of operating system .
@ -150,7 +129,6 @@ options:
- Linux
- Linux
default :
default :
- Linux
- Linux
required : false
public_ip_allocation_method :
public_ip_allocation_method :
description :
description :
- If a public IP address is created when creating the VM ( because a Network Interface was not provided ) ,
- If a public IP address is created when creating the VM ( because a Network Interface was not provided ) ,
@ -163,22 +141,22 @@ options:
- Static
- Static
aliases :
aliases :
- public_ip_allocation
- public_ip_allocation
required : false
open_ports :
open_ports :
description :
description :
- If a network interface is created when creating the VM , a security group will be created as well . For
- If a network interface is created when creating the VM , a security group will be created as well . For
Linux hosts a rule will be added to the security group allowing inbound TCP connections to the default
Linux hosts a rule will be added to the security group allowing inbound TCP connections to the default
SSH port 22 , and for Windows hosts ports 3389 and 5986 will be opened . Override the default open ports by
SSH port 22 , and for Windows hosts ports 3389 and 5986 will be opened . Override the default open ports by
providing a list of ports .
providing a list of ports .
default : null
required : false
network_interface_names :
network_interface_names :
description :
description :
- List of existing network interface names to add to the VM . If a network interface name is not provided
- List of existing network interface names to add to the VM . If a network interface name is not provided
when the VM is created , a default network interface will be created . In order for the module to create
when the VM is created , a default network interface will be created . In order for the module to create
a network interface , at least one Virtual Network with one Subnet must exist .
a network interface , at least one Virtual Network with one Subnet must exist .
default : null
virtual_network_resource_group :
required : false
description :
- When creating a virtual machine , if a specific virtual network from another resource group should be
used , use this parameter to specify the resource group to use .
version_added : " 2.4 "
virtual_network_name :
virtual_network_name :
description :
description :
- When creating a virtual machine , if a network interface name is not provided , one will be created .
- When creating a virtual machine , if a network interface name is not provided , one will be created .
@ -186,8 +164,6 @@ options:
Use this parameter to provide a specific virtual network instead .
Use this parameter to provide a specific virtual network instead .
aliases :
aliases :
- virtual_network
- virtual_network
default : null
required : false
subnet_name :
subnet_name :
description :
description :
- When creating a virtual machine , if a network interface name is not provided , one will be created .
- When creating a virtual machine , if a network interface name is not provided , one will be created .
@ -195,15 +171,12 @@ options:
Use this parameter to provide a specific subnet instead .
Use this parameter to provide a specific subnet instead .
aliases :
aliases :
- virtual_network
- virtual_network
default : null
required : false
remove_on_absent :
remove_on_absent :
description :
description :
- When removing a VM using state ' absent ' , also remove associated resources
- When removing a VM using state ' absent ' , also remove associated resources
- " It can be ' all ' or a list with any of the following: [ ' network_interfaces ' , ' virtual_storage ' , ' public_ips ' ] "
- " It can be ' all ' or a list with any of the following: [ ' network_interfaces ' , ' virtual_storage ' , ' public_ips ' ] "
- Any other input will be ignored
- Any other input will be ignored
default : [ ' all ' ]
default : [ ' all ' ]
required : false
extends_documentation_fragment :
extends_documentation_fragment :
- azure
- azure
@ -494,6 +467,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
open_ports = dict ( type = ' list ' ) ,
open_ports = dict ( type = ' list ' ) ,
network_interface_names = dict ( type = ' list ' , aliases = [ ' network_interfaces ' ] ) ,
network_interface_names = dict ( type = ' list ' , aliases = [ ' network_interfaces ' ] ) ,
remove_on_absent = dict ( type = ' list ' , default = [ ' all ' ] ) ,
remove_on_absent = dict ( type = ' list ' , default = [ ' all ' ] ) ,
virtual_network_resource_group = dict ( type = ' str ' ) ,
virtual_network_name = dict ( type = ' str ' , aliases = [ ' virtual_network ' ] ) ,
virtual_network_name = dict ( type = ' str ' , aliases = [ ' virtual_network ' ] ) ,
subnet_name = dict ( type = ' str ' , aliases = [ ' subnet ' ] ) ,
subnet_name = dict ( type = ' str ' , aliases = [ ' subnet ' ] ) ,
allocated = dict ( type = ' bool ' , default = True ) ,
allocated = dict ( type = ' bool ' , default = True ) ,
@ -523,6 +497,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
self . force = None
self . force = None
self . public_ip_allocation_method = None
self . public_ip_allocation_method = None
self . open_ports = None
self . open_ports = None
self . virtual_network_resource_group = None
self . virtual_network_name = None
self . virtual_network_name = None
self . subnet_name = None
self . subnet_name = None
self . allocated = None
self . allocated = None
@ -1200,12 +1175,19 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
self . log ( " NIC {0} does not exist. " . format ( network_interface_name ) )
self . log ( " NIC {0} does not exist. " . format ( network_interface_name ) )
virtual_network_resource_group = None
if self . virtual_network_resource_group :
virtual_network_resource_group = self . virtual_network_resource_group
else :
virtual_network_resource_group = self . resource_group
if self . virtual_network_name :
if self . virtual_network_name :
try :
try :
self . network_client . virtual_networks . list ( self . resource_group , self . virtual_network_name )
self . network_client . virtual_networks . list ( virtual_network_ resource_group, self . virtual_network_name )
virtual_network_name = self . virtual_network_name
virtual_network_name = self . virtual_network_name
except Exception as exc :
except CloudError :
self . fail ( " Error: fetching virtual network {0} - {1} " . format ( self . virtual_network_name , str ( exc ) ) )
self . fail ( " Error: fetching virtual network {0} - {1} " . format ( self . virtual_network_name , str ( exc ) ) )
else :
else :
# Find a virtual network
# Find a virtual network
no_vnets_msg = " Error: unable to find virtual network in resource group {0} . A virtual network " \
no_vnets_msg = " Error: unable to find virtual network in resource group {0} . A virtual network " \
@ -1240,7 +1222,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
subnet_id = None
subnet_id = None
try :
try :
subnets = self . network_client . subnets . list ( self . resource_group, virtual_network_name )
subnets = self . network_client . subnets . list ( virtual_network_ resource_group, virtual_network_name )
except CloudError :
except CloudError :
self . fail ( no_subnets_msg )
self . fail ( no_subnets_msg )