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