ansible/test/integration/targets/azure_rm_manageddisk/tasks/main.yml

204 lines
5.5 KiB
YAML
Raw Normal View History

- name: Prepare random number
set_fact:
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
parameter: {}
run_once: yes
- name: Clearing (if) previous disks were created
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
2019-04-24 06:43:52 +02:00
name: "md{{ rpfx }}{{ item }}"
managed_by: ''
state: absent
with_items:
2019-04-24 06:43:52 +02:00
- 1
- 2
- 3
- name: Test invalid account name (should give error)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "invalid_char$"
disk_size_gb: 1
register: output
ignore_errors: yes
check_mode: no
- name: Assert task failed
assert: { that: "output['failed'] == True" }
2019-04-24 06:43:52 +02:00
- name: Create managed disk (Check Mode)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
storage_account_type: "Standard_LRS"
disk_size_gb: 1
tags:
testing: testing
delete: never
register: output
2019-04-24 06:43:52 +02:00
check_mode: yes
2019-04-24 06:43:52 +02:00
- name: Assert status succeeded (Check Mode)
assert:
that:
- output.changed
2019-04-24 06:43:52 +02:00
- output.state
2019-04-24 06:43:52 +02:00
- name: Create new managed disk succesfully
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
2019-04-24 06:43:52 +02:00
name: "md{{ rpfx }}1"
storage_account_type: "Standard_LRS"
disk_size_gb: 1
tags:
testing: testing
delete: never
register: output
2019-04-24 06:43:52 +02:00
- name: Assert status succeeded and results include an Id value
assert:
that:
- output.changed
2019-04-24 06:43:52 +02:00
- output.state.disk_size_gb == 1
- output.state.id is defined
- output.state.os_type == None
- output.state.storage_account_type == "Standard_LRS"
- name: Copy disk to a new managed disk
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}2"
create_option: "copy"
source_uri: "{{ output.state.id }}"
disk_size_gb: 1
2019-04-24 06:43:52 +02:00
register: disk2
- name: Assert status succeeded and results include an Id value
assert:
that:
2019-04-24 06:43:52 +02:00
- disk2.changed
- disk2.state.id is defined
2019-04-24 06:43:52 +02:00
- name: Create disk to a new managed disk with zone and os type
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
2019-04-24 06:43:52 +02:00
name: "md{{ rpfx }}3"
source_uri: "{{ output.state.id }}"
disk_size_gb: 1
2019-04-24 06:43:52 +02:00
zone: "1"
os_type: windows
register: disk3
- name: Assert status succeeded and results include an Id value
assert:
that:
2019-04-24 06:43:52 +02:00
- disk3.changed
- disk3.state.id is defined
- disk3.state.zone == "1"
- disk3.state.os_type == "windows"
- name: Change storage account type to an invalid type
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
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" }
2019-04-24 06:43:52 +02:00
- name: Update disk options (os_type, account_type, size, tags)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
disk_size_gb: 2
2019-04-24 06:43:52 +02:00
os_type: linux
storage_account_type: "StandardSSD_LRS"
2019-04-24 06:43:52 +02:00
tags:
galaxy: "no"
delete: never
register: output
- assert:
that:
- output.changed
2019-04-24 06:43:52 +02:00
- output.state.storage_account_type == "StandardSSD_LRS"
- output.state.disk_size_gb == 2
- "output.state.tags | length == 2"
- "output.state.tags.galaxy == 'no'"
- output.state.os_type == 'linux'
- name: Gather facts to one specific disk
azure_rm_manageddisk_facts:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
- assert:
that:
- "azure_managed_disk | length == 1"
2019-04-24 06:43:52 +02:00
- azure_managed_disk[0].storage_account_type == "StandardSSD_LRS"
- azure_managed_disk[0].disk_size_gb == 2
- "azure_managed_disk[0].os_type == 'linux'"
- set_fact:
parameter: "{{parameter |combine({item.key: item.value})}}"
when: "{{item.key not in ['id', 'changed'] and item.value != None}}"
with_dict: "{{ azure_managed_disk[0] }}"
- name: Create disk with facts return value
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
location: "{{ parameter.location }}"
name: "{{ parameter.name }}"
storage_account_type: "{{ parameter.storage_account_type }}"
disk_size_gb: "{{ parameter.disk_size_gb }}"
create_option: "{{ parameter.create_option }}"
tags: "{{ parameter.tags }}"
register: output
- assert:
that:
- not output.changed
- name: Delete managed disk (Check Mode)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
state: absent
register: output
check_mode: yes
- name: Assert status succeeded
assert:
that:
- output.changed
- output.state
- name: Delete all managed disk
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}{{ item }}"
managed_by: ''
state: absent
with_items:
- 1
- 2
- 3
- name: Delete virtual machine
azure_rm_virtualmachine:
resource_group: "{{ resource_group }}"
name: "tr{{ rpfx }}"
state: absent
vm_size: Standard_DS1_v2
- name: Delete public ip
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Static
name: "tr{{ rpfx }}"
state: absent