Skip to content

Commit aec7c1d

Browse files
committed
Support managed_disk_type
Add support for specifying managed_disk_type. This is a prerequisite for supporting snapshots. Also fixed variable names to include role prefix to prevent variable collisions. fixes #99
1 parent 1572d52 commit aec7c1d

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

.ansible-lint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
profile: production
2+
3+
exclude_paths:
4+
- tests/integration/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bugfixes:
2+
- Adding managed_disk_type as possible option in role azure_virtual_machine_with_public_ip
3+
4+
trivial:
5+
- Renamed register variables in azure_virtual_machine_with_public_ip to include pre-pended
6+
role name to prevent variable name collisions.

roles/azure_virtual_machine_with_public_ip/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Contains the following:
4545
- **name**: (Required) Name of the availability set.
4646
- **platform_fault_domain_count**: Fault domains define the group of virtual machines that share a common power source and network switch. Should be between 1 and 3.
4747
- **platform_update_domain_count**: Update domains indicate groups of virtual machines and underlying physical hardware that can be rebooted at the same time.
48+
- **sku**: Define if the availability set supports managed disks. Choices are Classic and Aligned, Default is Classic. Aligned is needed when specifying managed_disk_type for os_disk and data_disks.
4849
* **azure_virtual_machine_with_public_ip_delete_resource_group**: Relevant for **delete** operation. Change to true in case Resource Group deletion should be done as part of this role deletion (default: false)
4950

5051
Limitations

roles/azure_virtual_machine_with_public_ip/meta/argument_specs.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ argument_specs:
7070
- 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 name and resource_group.
7171
- For Marketplace images, a dict with the keys publisher, offer, sku, and version.
7272
- Set O(version=latest) to get the most recent version of a given image.
73+
managed_disk_type:
74+
type: "str"
75+
description:
76+
- Managed OS disk type.
77+
- Create OS disk with managed disk if defined.
78+
- If not defined, the OS disk will be created with virtual hard disk (VHD).
79+
choices:
80+
- "Standard_LRS"
81+
- "StandardSSD_LRS"
82+
- "StandardSSD_ZRS"
83+
- "Premium_LRS"
84+
- "Premium_ZRS"
85+
- "UltraSSD_LRS"
86+
required: false
7387
ssh_pw_enabled:
7488
description: Enable/disable SSH passwords.
7589
choices: ['yes', 'no']
@@ -93,8 +107,6 @@ argument_specs:
93107
description:
94108
- Initial disk size in GB for blank data disks. Cannot be larger than 1023 GB.
95109
- Can only be modified when VM is deallocated.
96-
managed_disk_type:
97-
description: Managed data disk type.
98110
storage_account_name:
99111
description: Name of an existing storage account that supports creation of VHD blobs.
100112
storage_blob_name:
@@ -115,3 +127,7 @@ argument_specs:
115127
- Should be between 1 and 3.
116128
platform_update_domain_count:
117129
description: Update domains indicate groups of virtual machines and underlying physical hardware that can be rebooted at the same time.
130+
sku:
131+
description: Define if the availability set supports managed disks.
132+
choices: ['Classic', 'Aligned']
133+
default: 'Classic'

roles/azure_virtual_machine_with_public_ip/tasks/create.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ansible.builtin.fail:
2020
msg: Azure location must be defined as azure_virtual_machine_with_public_ip_region
2121
when:
22-
- rg_info.resourcegroups | length == 0
22+
- azure_virtual_machine_with_public_ip_rg_info.resourcegroups | length == 0
2323
- azure_virtual_machine_with_public_ip_region is not defined
2424

2525
- name: Create resource group if it doesn't already exists
@@ -30,7 +30,7 @@
3030
azure_manage_resource_group_name: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
3131
azure_manage_resource_group_region: "{{ azure_virtual_machine_with_public_ip_region }}"
3232
azure_manage_resource_group_tags: "{{ azure_virtual_machine_with_public_ip_tags | default({}) }}"
33-
when: rg_info.resourcegroups | length == 0
33+
when: azure_virtual_machine_with_public_ip_rg_info.resourcegroups | length == 0
3434

3535
# Set tags for VM
3636
- name: Set tags for VM
@@ -44,10 +44,10 @@
4444
- name: No network interface specified -> get virtual network info
4545
azure.azcollection.azure_rm_virtualnetwork_info:
4646
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
47-
register: vnet_info
47+
register: azure_virtual_machine_with_public_ip_vnet_info
4848

4949
- name: Create virtual network if not already exist
50-
when: vnet_info.virtualnetworks | length == 0
50+
when: azure_virtual_machine_with_public_ip_vnet_info.virtualnetworks | length == 0
5151
block:
5252
- name: Check virtual network CIDR address prefixes
5353
ansible.builtin.fail:
@@ -75,7 +75,7 @@
7575
- name: Refresh virtual network info
7676
azure.azcollection.azure_rm_virtualnetwork_info:
7777
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
78-
register: vnet_info
78+
register: azure_virtual_machine_with_public_ip_vnet_info
7979

8080
- name: Create default public ip for default nic
8181
azure.azcollection.azure_rm_publicipaddress:
@@ -91,8 +91,8 @@
9191
azure_manage_network_interface_resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
9292
azure_manage_network_interface_interface:
9393
name: "{{ vm_name }}"
94-
vnet_name: "{{ vnet_info.virtualnetworks[0].name }}" # This is how the azure_rm_virtualmachine module creates its default network interface - using the first vnet
95-
subnet_name: "{{ vnet_info.virtualnetworks[0].subnets[0].name }}"
94+
vnet_name: "{{ azure_virtual_machine_with_public_ip_vnet_info.virtualnetworks[0].name }}" # This is how the azure_rm_virtualmachine module creates its default network interface - using the first vnet
95+
subnet_name: "{{ azure_virtual_machine_with_public_ip_vnet_info.virtualnetworks[0].subnets[0].name }}"
9696
ip_configurations:
9797
- name: default
9898
primary: true
@@ -108,7 +108,7 @@
108108
azure.azcollection.azure_rm_availabilityset_info:
109109
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
110110
name: "{{ azure_virtual_machine_with_public_ip_availability_set.name }}"
111-
register: aset_info
111+
register: azure_virtual_machine_with_public_ip_aset_info
112112
when: azure_virtual_machine_with_public_ip_availability_set is defined
113113

114114
- name: Create availability set
@@ -117,11 +117,12 @@
117117
name: "{{ azure_virtual_machine_with_public_ip_availability_set.name }}"
118118
platform_update_domain_count: "{{ azure_virtual_machine_with_public_ip_availability_set.platform_update_domain_count | default(omit) }}"
119119
platform_fault_domain_count: "{{ azure_virtual_machine_with_public_ip_availability_set.platform_fault_domain_count | default(omit) }}"
120+
sku: "{{ azure_virtual_machine_with_public_ip_availability_set.sku | default(omit) }}"
120121
tags:
121122
_own_availability_set_: "{{ azure_virtual_machine_with_public_ip_availability_set.name }}"
122123
when:
123124
- azure_virtual_machine_with_public_ip_availability_set is defined
124-
- aset_info.ansible_info.azure_availabilitysets | length == 0
125+
- azure_virtual_machine_with_public_ip_aset_info.ansible_info.azure_availabilitysets | length == 0
125126

126127
# Create/update VM
127128
- name: Create/Update VM
@@ -131,6 +132,7 @@
131132
vm_size: "{{ azure_virtual_machine_with_public_ip_vm.size | default(omit) }}"
132133
network_interfaces: "{{ azure_virtual_machine_with_public_ip_vm.network_interfaces | default(vm_name) }}"
133134
os_type: "{{ azure_virtual_machine_with_public_ip_vm.os | default(omit) }}"
135+
managed_disk_type: "{{ azure_virtual_machine_with_public_ip_vm.managed_disk_type | default(omit) }}"
134136
availability_set: "{{ azure_virtual_machine_with_public_ip_availability_set.name | default(omit) }}"
135137
image: "{{ azure_virtual_machine_with_public_ip_vm.image | default(omit) }}"
136138
admin_username: "{{ azure_virtual_machine_with_public_ip_vm.admin_username | default(omit) }}"

roles/azure_virtual_machine_with_public_ip/tasks/delete.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
name: "{{ azure_virtual_machine_with_public_ip_availability_set.name }}"
1919
tags:
2020
_own_availability_set_
21-
register: _aset_info
21+
register: azure_virtual_machine_with_public_ip_aset_info
2222
when: azure_virtual_machine_with_public_ip_availability_set is defined
2323

2424
- name: Delete availability set if created by role
@@ -28,7 +28,7 @@
2828
state: absent
2929
when:
3030
- azure_virtual_machine_with_public_ip_availability_set is defined
31-
- _aset_info.ansible_info.azure_availabilitysets | length == 1
31+
- azure_virtual_machine_with_public_ip_aset_info.ansible_info.azure_availabilitysets | length == 1
3232
- azure_virtual_machine_with_public_ip_remove_on_absent in ['all', 'all_autocreated']
3333

3434
# Delete Virtual network if created by role
@@ -38,15 +38,15 @@
3838
name: "{{ vm_name }}"
3939
tags:
4040
_own_vnet_
41-
register: _vnet_info
41+
register: azure_virtual_machine_with_public_ip_vnet_info
4242

4343
- name: Delete Virtual network if created by role
4444
azure.azcollection.azure_rm_virtualnetwork:
4545
resource_group: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
4646
name: "{{ vm_name }}"
4747
state: absent
4848
when:
49-
- _vnet_info.virtualnetworks | length == 1
49+
- azure_virtual_machine_with_public_ip_vnet_info.virtualnetworks | length == 1
5050
- azure_virtual_machine_with_public_ip_remove_on_absent in ['all', 'all_autocreated']
5151

5252
- name: Delete Resource group if requested

roles/azure_virtual_machine_with_public_ip/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
- name: Get resource group info
77
azure.azcollection.azure_rm_resourcegroup_info:
88
name: "{{ azure_virtual_machine_with_public_ip_resource_group }}"
9-
register: rg_info
9+
register: azure_virtual_machine_with_public_ip_rg_info
1010

1111
- name: Fail when resource group doesn't exist
1212
ansible.builtin.fail:
1313
msg: Resource group {{ azure_virtual_machine_with_public_ip_resource_group }} does not exist
1414
when:
15-
- rg_info.resourcegroups | length == 0
15+
- azure_virtual_machine_with_public_ip_rg_info.resourcegroups | length == 0
1616
- azure_virtual_machine_with_public_ip_operation != 'create'
1717

1818
- name: Power Off VM

0 commit comments

Comments
 (0)