Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ephemeral OS disk for azure_rm_virtualmachine #124

Merged
merged 9 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion plugins/modules/azure_rm_virtualmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@
- Windows
- Linux
default: Linux
ephemeral_os_disk:
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
default: False
data_disks:
description:
- Describes list of data disks.
Expand Down Expand Up @@ -847,6 +853,7 @@ def __init__(self):
vm_identity=dict(type='str', choices=['SystemAssigned']),
winrm=dict(type='list'),
boot_diagnostics=dict(type='dict'),
ephemeral_os_disk=dict(type='bool'),
)

self.resource_group = None
Expand Down Expand Up @@ -891,6 +898,7 @@ def __init__(self):
self.license_type = None
self.vm_identity = None
self.boot_diagnostics = None
self.ephemeral_os_disk = None

self.results = dict(
changed=False,
Expand Down Expand Up @@ -1054,6 +1062,13 @@ def exec_module(self, **kwargs):
differences = []
current_nics = []
results = vm_dict
current_osdisk = vm_dict['properties']['storageProfile']['osDisk']
current_ephemeral = current_osdisk.get('diffDiskSettings', None)

if self.ephemeral_os_disk and current_ephemeral is None:
self.fail('Ephemeral OS disk not updatable: virtual machine ephemeral OS disk is {0}'.format(self.ephemeral_os_disk))
Fred-sun marked this conversation as resolved.
Show resolved Hide resolved
elif not self.ephemeral_os_disk and current_ephemeral is not None:
self.fail('Ephemeral OS disk not updatable: virtual machine ephemeral OS disk is {0}'.format(self.ephemeral_os_disk))

# Try to determine if the VM needs to be updated
if self.network_interface_names:
Expand Down Expand Up @@ -1294,7 +1309,8 @@ def exec_module(self, **kwargs):
managed_disk=managed_disk,
create_option=self.compute_models.DiskCreateOptionTypes.from_image,
caching=self.os_disk_caching,
disk_size_gb=self.os_disk_size_gb
disk_size_gb=self.os_disk_size_gb,
diff_disk_settings=self.compute_models.DiffDiskSettings(option='Local') if self.ephemeral_os_disk else None
),
image_reference=image_reference,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
- include_tasks: setup.yml

- name: Create minimal VM with defaults
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
admin_username: "testuser"
admin_password: "Pass123$$$abx!"
vm_size: Standard_DS2_v2
image:
offer: UbuntuServer
publisher: Canonical
sku: 16.04-LTS
version: latest
register: vm_output

- name: Generalize VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
generalized: yes

- name: Create an image from VM
azure_rm_image:
resource_group: "{{ resource_group }}"
source: "{{ vm_name }}"
name: testimage
os_type: Linux
register: output

- assert:
that:
- output.changed

- name: Create virtual machine ephmeral OS disk
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}-02"
admin_username: "testuser"
admin_password: "Pass123$$$abx!"
vm_size: Standard_DS2_v2
os_disk_caching: ReadOnly
ephemeral_os_disk: True
image: testimage
register: output

- assert:
that:
- output.changed
- output.ansible_facts.azure_vm.properties.storageProfile.osDisk.diffDiskSettings.option == 'Local'

- name: Check virtual machine ephmeral OS disk idempotent
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}-02"
admin_username: "testuser"
admin_password: "Pass123$$$abx!"
vm_size: Standard_DS2_v2
os_disk_caching: ReadOnly
ephemeral_os_disk: True
image: testimage
register: output

- assert:
that:
- not output.changed

- name: Check virtual machine ephmeral OS disk can't update
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}-02"
admin_username: "testuser"
admin_password: "Pass123$$$abx!"
vm_size: Standard_DS2_v2
os_disk_caching: ReadOnly
ephemeral_os_disk: False
image: testimage
ignore_errors: yes
register: ouput

- assert:
that:
- not output.changed

- name: Delete VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}"
state: absent

- name: Delete VM
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "{{ vm_name }}-02"
state: absent

- name: Create an image from VM
azure_rm_image:
resource_group: "{{ resource_group }}"
name: testimage
state: absent