2018-06-12 02:52:07 +00:00
|
|
|
- name: Prepare random number
|
2017-08-29 21:59:06 +00:00
|
|
|
set_fact:
|
2018-06-12 02:52:07 +00:00
|
|
|
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
run_once: yes
|
2017-08-29 21:59:06 +00:00
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Clearing (if) previous disks were created
|
2017-08-29 21:59:06 +00:00
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{item }}"
|
2017-08-29 21:59:06 +00:00
|
|
|
state: absent
|
2017-12-20 21:53:14 +00:00
|
|
|
with_items:
|
2018-06-12 02:52:07 +00:00
|
|
|
- "md{{ rpfx }}2"
|
|
|
|
- "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
|
|
|
|
- name: Create managed disk (Check Mode)
|
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
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:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2017-08-29 21:59:06 +00:00
|
|
|
name: "invalid_char$"
|
|
|
|
disk_size_gb: 1
|
|
|
|
state: present
|
2017-12-20 21:53:14 +00:00
|
|
|
register: output
|
|
|
|
ignore_errors: yes
|
2017-08-29 21:59:06 +00:00
|
|
|
check_mode: no
|
|
|
|
|
|
|
|
- name: Assert task failed
|
|
|
|
assert: { that: "output['failed'] == True" }
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Create new managed disk succesfully
|
2017-08-29 21:59:06 +00:00
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
storage_account_type: "Standard_LRS"
|
|
|
|
disk_size_gb: 1
|
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: output
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Assert status succeeded and results include an Id value
|
2017-08-29 21:59:06 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
- output.state.id is defined
|
|
|
|
|
|
|
|
- name: Copy disk to a new managed disk
|
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}2"
|
2017-08-29 21:59:06 +00:00
|
|
|
create_option: "copy"
|
|
|
|
source_resource_uri: "{{ output.state.id }}"
|
|
|
|
disk_size_gb: 1
|
|
|
|
register: copy
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Assert status succeeded and results include an Id value
|
2017-08-29 21:59:06 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- copy.changed
|
|
|
|
- copy.state.id is defined
|
|
|
|
|
|
|
|
- name: Update a new disk without changes
|
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
storage_account_type: "Standard_LRS"
|
|
|
|
disk_size_gb: 1
|
|
|
|
register: output
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Assert status succeeded and results include an Id value
|
2017-08-29 21:59:06 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- not output.changed
|
|
|
|
- output.state.id is defined
|
|
|
|
|
|
|
|
- name: Change storage account type to an invalid type
|
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
storage_account_type: "PremiumL"
|
|
|
|
disk_size_gb: 1
|
|
|
|
register: output
|
2017-12-20 21:53:14 +00:00
|
|
|
ignore_errors: yes
|
2017-08-29 21:59:06 +00:00
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Assert storage account type change failed
|
2017-08-29 21:59:06 +00:00
|
|
|
assert: { that: "output['failed'] == True" }
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Change disk size to incompatible size
|
2017-08-29 21:59:06 +00:00
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
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:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
disk_size_gb: 2
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Assert status succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Change disk to Premium
|
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
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 }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
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 }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
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 }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
|
|
|
|
- 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"
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Create virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
address_prefixes: "10.10.0.0/16"
|
|
|
|
|
|
|
|
- name: Add subnet
|
|
|
|
azure_rm_subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
address_prefix: "10.10.0.0/24"
|
2018-06-12 02:52:07 +00:00
|
|
|
virtual_network: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
|
|
|
|
- name: Create public ip
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
allocation_method: Static
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
|
|
|
|
- name: Create security group
|
|
|
|
azure_rm_securitygroup:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
|
|
|
|
- name: Create NIC
|
|
|
|
azure_rm_networkinterface:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "tr{{ rpfx }}"
|
|
|
|
virtual_network: "tr{{ rpfx }}"
|
|
|
|
subnet: "tr{{ rpfx }}"
|
|
|
|
public_ip_name: "tr{{ rpfx }}"
|
|
|
|
security_group: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
|
|
|
|
- name: Create virtual machine
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
admin_username: adminuser
|
|
|
|
admin_password: Password123!
|
|
|
|
os_type: Linux
|
|
|
|
managed_disk_type: Premium_LRS
|
|
|
|
vm_size: Standard_DS1_v2
|
2018-06-12 02:52:07 +00:00
|
|
|
network_interfaces: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
image:
|
|
|
|
offer: UbuntuServer
|
|
|
|
publisher: Canonical
|
|
|
|
sku: 16.04-LTS
|
|
|
|
version: latest
|
|
|
|
|
|
|
|
- name: Mount the disk to virtual machine (check mode)
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 2
|
2018-06-12 02:52:07 +00:00
|
|
|
managed_by: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: mounted
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- not mounted.state.managed_by
|
|
|
|
|
|
|
|
- name: Mount the disk to virtual machine
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 2
|
2018-06-12 02:52:07 +00:00
|
|
|
managed_by: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: mounted
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
2018-06-12 02:52:07 +00:00
|
|
|
- "'tr{{ rpfx }}' in mounted.state.managed_by"
|
2017-12-20 21:53:14 +00:00
|
|
|
|
|
|
|
- name: Mount the disk to virtual machine (idempotent)
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 2
|
2018-06-12 02:52:07 +00:00
|
|
|
managed_by: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: mounted
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- not mounted.changed
|
2018-06-12 02:52:07 +00:00
|
|
|
- "'tr{{ rpfx }}' in mounted.state.managed_by"
|
2017-12-20 21:53:14 +00:00
|
|
|
|
|
|
|
- name: Unmount the disk to virtual machine (check mode)
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 2
|
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
check_mode: yes
|
|
|
|
register: mounted
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- mounted.changed
|
|
|
|
|
|
|
|
- name: Unmount the disk to virtual machine
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 2
|
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: mounted
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- mounted.changed
|
|
|
|
- not mounted.state.managed_by
|
|
|
|
|
|
|
|
- name: Unmount the disk to virtual machine (idempotent)
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 2
|
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: mounted
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- not mounted.changed
|
|
|
|
- not mounted.state.managed_by
|
|
|
|
|
|
|
|
- name: Update disk size
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 4
|
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.disk_size_gb == 4
|
|
|
|
|
|
|
|
- name: Attach the disk to virtual machine again
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
disk_size_gb: 4
|
2018-06-12 02:52:07 +00:00
|
|
|
managed_by: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: mounted
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- mounted.changed
|
2018-06-12 02:52:07 +00:00
|
|
|
- "'tr{{ rpfx }}' in mounted.state.managed_by"
|
2017-12-20 21:53:14 +00:00
|
|
|
|
|
|
|
- name: Change disk size to incompatible size
|
|
|
|
azure_rm_managed_disk:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-12-20 21:53:14 +00:00
|
|
|
state: absent
|
2018-06-12 02:52:07 +00:00
|
|
|
managed_by: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
register: output
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: Assert delete failed since disk is attached to VM
|
|
|
|
assert: { that: "output['failed'] == True" }
|
|
|
|
|
2017-08-29 21:59:06 +00:00
|
|
|
- name: Delete managed disk (Check Mode)
|
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
state: absent
|
2017-12-20 21:53:14 +00:00
|
|
|
register: output
|
2017-08-29 21:59:06 +00:00
|
|
|
check_mode: yes
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Assert status succeeded
|
2017-08-29 21:59:06 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
- output.state
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Delete managed disk
|
2017-08-29 21:59:06 +00:00
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}2"
|
2017-08-29 21:59:06 +00:00
|
|
|
state: absent
|
|
|
|
check_mode: no
|
|
|
|
|
2017-12-20 21:53:14 +00:00
|
|
|
- name: Delete copied managed disk
|
2017-08-29 21:59:06 +00:00
|
|
|
azure_rm_managed_disk:
|
2017-12-20 21:53:14 +00:00
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "md{{ rpfx }}1"
|
2017-08-29 21:59:06 +00:00
|
|
|
disk_size_gb: 2
|
|
|
|
state: absent
|
2017-12-20 21:53:14 +00:00
|
|
|
check_mode: no
|
|
|
|
|
|
|
|
- name: Delete virtual machine
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "tr{{ rpfx }}"
|
2017-12-20 21:53:14 +00:00
|
|
|
state: absent
|
|
|
|
vm_size: Standard_DS1_v2
|
2018-06-12 02:52:07 +00:00
|
|
|
|
|
|
|
- name: Delete public ip
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
allocation_method: Static
|
|
|
|
name: "tr{{ rpfx }}"
|
|
|
|
state: absent
|