|
|
|
@ -305,6 +305,11 @@ options:
|
|
|
|
|
type: bool
|
|
|
|
|
default: false
|
|
|
|
|
version_added: "2.7"
|
|
|
|
|
zones:
|
|
|
|
|
description:
|
|
|
|
|
- A list of Availability Zones for your virtual machine
|
|
|
|
|
type: list
|
|
|
|
|
version_added: "2.8"
|
|
|
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
|
- azure
|
|
|
|
@ -498,6 +503,16 @@ EXAMPLES = '''
|
|
|
|
|
remove_on_absent:
|
|
|
|
|
- network_interfaces
|
|
|
|
|
- virtual_storage
|
|
|
|
|
|
|
|
|
|
- name: Create a VM with an Availability Zone
|
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
|
resource_group: Testing
|
|
|
|
|
name: testvm001
|
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
|
admin_username: adminUser
|
|
|
|
|
admin_password: password01
|
|
|
|
|
image: customimage001
|
|
|
|
|
zones: [1]
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
@ -737,7 +752,8 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
generalized=dict(type='bool', default=False),
|
|
|
|
|
data_disks=dict(type='list'),
|
|
|
|
|
plan=dict(type='dict'),
|
|
|
|
|
accept_terms=dict(type='bool', default=False)
|
|
|
|
|
accept_terms=dict(type='bool', default=False),
|
|
|
|
|
zones=dict(type='list')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.resource_group = None
|
|
|
|
@ -778,6 +794,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
self.data_disks = None
|
|
|
|
|
self.plan = None
|
|
|
|
|
self.accept_terms = None
|
|
|
|
|
self.zones = None
|
|
|
|
|
|
|
|
|
|
self.results = dict(
|
|
|
|
|
changed=False,
|
|
|
|
@ -797,6 +814,9 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
# make sure options are lower case
|
|
|
|
|
self.remove_on_absent = set([resource.lower() for resource in self.remove_on_absent])
|
|
|
|
|
|
|
|
|
|
# convert elements to ints
|
|
|
|
|
self.zones = [int(i) for i in self.zones] if self.zones else None
|
|
|
|
|
|
|
|
|
|
changed = False
|
|
|
|
|
powerstate_change = None
|
|
|
|
|
results = dict()
|
|
|
|
@ -968,6 +988,12 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
changed = True
|
|
|
|
|
powerstate_change = 'generalized'
|
|
|
|
|
|
|
|
|
|
vm_dict['zones'] = [int(i) for i in vm_dict['zones']] if 'zones' in vm_dict and vm_dict['zones'] else None
|
|
|
|
|
if self.zones != vm_dict['zones']:
|
|
|
|
|
self.log("CHANGED: virtual machine {0} zones".format(self.name))
|
|
|
|
|
differences.append('Zones')
|
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
|
|
self.differences = differences
|
|
|
|
|
|
|
|
|
|
elif self.state == 'absent':
|
|
|
|
@ -1014,6 +1040,9 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
parsed_availability_set.get('name'))
|
|
|
|
|
availability_set_resource = self.compute_models.SubResource(id=availability_set.id)
|
|
|
|
|
|
|
|
|
|
if self.zones:
|
|
|
|
|
self.fail("Parameter error: you can't use Availability Set and Availability Zones at the same time")
|
|
|
|
|
|
|
|
|
|
# Get defaults
|
|
|
|
|
if not self.network_interface_names:
|
|
|
|
|
default_nic = self.create_default_nic()
|
|
|
|
@ -1081,7 +1110,8 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
network_interfaces=nics
|
|
|
|
|
),
|
|
|
|
|
availability_set=availability_set_resource,
|
|
|
|
|
plan=plan
|
|
|
|
|
plan=plan,
|
|
|
|
|
zones=self.zones,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if self.admin_password:
|
|
|
|
@ -1220,6 +1250,10 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
else:
|
|
|
|
|
image_reference = None
|
|
|
|
|
|
|
|
|
|
# You can't change a vm zone
|
|
|
|
|
if vm_dict['zones'] != self.zones:
|
|
|
|
|
self.fail("You can't change the Availability Zone of a virtual machine (have: {0}, want: {1})".format(vm_dict['zones'], self.zones))
|
|
|
|
|
|
|
|
|
|
if 'osProfile' in vm_dict['properties']:
|
|
|
|
|
os_profile = self.compute_models.OSProfile(
|
|
|
|
|
admin_username=vm_dict['properties'].get('osProfile', {}).get('adminUsername'),
|
|
|
|
@ -1810,8 +1844,9 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
|
|
|
|
pip = None
|
|
|
|
|
if self.public_ip_allocation_method != 'Disabled':
|
|
|
|
|
self.results['actions'].append('Created default public IP {0}'.format(self.name + '01'))
|
|
|
|
|
pip_info = self.create_default_pip(self.resource_group, self.location, self.name + '01', self.public_ip_allocation_method)
|
|
|
|
|
pip = self.network_models.PublicIPAddress(id=pip_info.id, location=pip_info.location, resource_guid=pip_info.resource_guid)
|
|
|
|
|
sku = self.network_models.PublicIPAddressSku(name="Standard") if self.zones else None
|
|
|
|
|
pip_info = self.create_default_pip(self.resource_group, self.location, self.name + '01', self.public_ip_allocation_method, sku=sku)
|
|
|
|
|
pip = self.network_models.PublicIPAddress(id=pip_info.id, location=pip_info.location, resource_guid=pip_info.resource_guid, sku=sku)
|
|
|
|
|
|
|
|
|
|
self.results['actions'].append('Created default security group {0}'.format(self.name + '01'))
|
|
|
|
|
group = self.create_default_securitygroup(self.resource_group, self.location, self.name + '01', self.os_type,
|
|
|
|
|