mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
4c36286779
* First version of managed disks: Multiple methods for creating, one get and one delete * My name is too cool to be there * Passing pep8 test * Create and delete empty working * Module for testing, lacks sense of setting state changed for unchanged operations * Checking that actual changes are done to update status changed * First version of the integration test * Adding the dictionary to translate the facts, without using serializer * Adding the serializer to managed disk * Using native serializer in managed disks facts * Added DiskSku to pass the whole class to the disk instead of a string * Bumping version * Passing sanity checks * Aparently they Id is not returned by the serilizer * Integration test * Latest version * Using my own serializer, the one in commons is not working for me * Managed disks module support for ansible * Updating my github account username in the file * Sanity checks were missing in facts and integration test * Fixing typo in source_resource_uri and removed AzureHTTPErrors * Update tags are working now * Integration test for tags * Added support for tags, added check mode, corrected style
221 lines
No EOL
5.8 KiB
YAML
221 lines
No EOL
5.8 KiB
YAML
- name: Setup variables...
|
|
set_fact:
|
|
managed_disk1: "{{ resource_group | hash('md5') | truncate(24, True, '') }}"
|
|
managed_disk2: "{{ resource_group | hash('md5') | truncate(18, True, '') }}"
|
|
|
|
- name: Clearing (if) previous disks were created (1/2)
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk2 }}"
|
|
state: absent
|
|
|
|
- name: Clearing (if) previous disks were created (2/2)
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
state: absent
|
|
|
|
- name: Create managed disk (Check Mode)
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
disk_size_gb: 1
|
|
tags:
|
|
testing: testing
|
|
delete: never
|
|
register: output
|
|
check_mode: yes
|
|
|
|
- name: Assert status succeeded (Check Mode)
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
- output.state
|
|
|
|
- name: Test invalid account name (should give error)
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "invalid_char$"
|
|
disk_size_gb: 1
|
|
state: present
|
|
register: output
|
|
ignore_errors: yes
|
|
check_mode: no
|
|
|
|
- name: Assert task failed
|
|
assert: { that: "output['failed'] == True" }
|
|
|
|
- name: Create new managed disk succesfully
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
storage_account_type: "Standard_LRS"
|
|
disk_size_gb: 1
|
|
tags:
|
|
testing: testing
|
|
delete: never
|
|
register: output
|
|
|
|
- name: Assert status succeeded and results include an Id value
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
- output.state.id is defined
|
|
|
|
- name: Copy disk to a new managed disk
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk2 }}"
|
|
create_option: "copy"
|
|
source_resource_uri: "{{ output.state.id }}"
|
|
disk_size_gb: 1
|
|
register: copy
|
|
|
|
- name: Assert status succeeded and results include an Id value
|
|
assert:
|
|
that:
|
|
- copy.changed
|
|
- copy.state.id is defined
|
|
|
|
- name: Update a new disk without changes
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
storage_account_type: "Standard_LRS"
|
|
disk_size_gb: 1
|
|
register: output
|
|
|
|
- name: Assert status succeeded and results include an Id value
|
|
assert:
|
|
that:
|
|
- not output.changed
|
|
- output.state.id is defined
|
|
|
|
- name: Change storage account type to an invalid type
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
storage_account_type: "PremiumL"
|
|
disk_size_gb: 1
|
|
register: output
|
|
ignore_errors: yes
|
|
|
|
- name: Assert storage account type change failed
|
|
assert: { that: "output['failed'] == True" }
|
|
|
|
- name: Change disk size to incompatible size
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
disk_size_gb: 30000
|
|
register: output
|
|
ignore_errors: yes
|
|
|
|
- name: Assert disk size change to incompatible size (>4095) failure
|
|
assert: { that: "output['failed'] == True" }
|
|
|
|
- name: Change disk to bigger size
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
disk_size_gb: 2
|
|
register: output
|
|
|
|
- name: Assert status succeeded
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
|
|
- name: Change disk to Premium
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
storage_account_type: "Premium_LRS"
|
|
disk_size_gb: 2
|
|
register: output
|
|
|
|
- name: Assert status succeeded
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
|
|
- name: Update disk tags
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
disk_size_gb: 2
|
|
tags:
|
|
testing: testing
|
|
delete: never
|
|
galaxy: 'no'
|
|
register: output
|
|
|
|
- name: Assert disk incremented tags
|
|
assert:
|
|
that:
|
|
- "output.state.tags | length == 3"
|
|
- "output.state.tags.galaxy == 'no'"
|
|
|
|
- name: Update disk tags
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
disk_size_gb: 2
|
|
tags:
|
|
testing: testing
|
|
delete: never
|
|
register: output
|
|
|
|
- name: Assert disk tags are 2
|
|
assert:
|
|
that:
|
|
- "output.state.tags | length == 2"
|
|
- "output.state.tags.testing == 'testing'"
|
|
- "output.state.tags.delete == 'never'"
|
|
|
|
- name: Gather facts to one specific disk
|
|
azure_rm_managed_disk_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
|
|
- assert:
|
|
that:
|
|
- "azure_managed_disk | length == 1"
|
|
|
|
- name: Gather facts
|
|
azure_rm_managed_disk_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
- assert:
|
|
that:
|
|
- "azure_managed_disk | length > 0"
|
|
|
|
- name: Delete managed disk (Check Mode)
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
state: absent
|
|
disk_size_gb: 2
|
|
check_mode: yes
|
|
|
|
- name: Assert status succeeded
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
- output.state
|
|
|
|
- name: Delete managed disk
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk2 }}"
|
|
disk_size_gb: 1
|
|
state: absent
|
|
check_mode: no
|
|
|
|
- name: Delete copied managed disk
|
|
azure_rm_managed_disk:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ managed_disk1 }}"
|
|
disk_size_gb: 2
|
|
state: absent
|
|
check_mode: no |