e4194b20db
* add availability set for vm * add test * add import * fix * add test assert and output * fix lint and version added * add null check * fix mirror * fix mirror
208 lines
No EOL
5.7 KiB
YAML
208 lines
No EOL
5.7 KiB
YAML
- name: Delete virtual machine
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
state: absent
|
|
vm_size: Standard_A0
|
|
register: output
|
|
|
|
- name: Create storage account name
|
|
set_fact:
|
|
storage_account: "{{ resource_group | hash('md5') | truncate(24, True, '') }}"
|
|
|
|
- name: Create storage account
|
|
azure_rm_storageaccount:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ storage_account }}"
|
|
account_type: Standard_LRS
|
|
|
|
- name: Create an availability set
|
|
azure_rm_availabilityset:
|
|
name: "avbs{{ resource_group | hash('md5') | truncate(7, True, '') }}"
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
- name: Create virtual network
|
|
azure_rm_virtualnetwork:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm001
|
|
address_prefixes: "10.10.0.0/16"
|
|
|
|
- name: Add subnet
|
|
azure_rm_subnet:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm001
|
|
address_prefix: "10.10.0.0/24"
|
|
virtual_network: testvm001
|
|
|
|
- name: Create public ip
|
|
azure_rm_publicipaddress:
|
|
resource_group: "{{ resource_group }}"
|
|
allocation_method: Static
|
|
name: testvm001
|
|
|
|
- name: Create security group
|
|
azure_rm_securitygroup:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm001
|
|
|
|
- name: Create NIC
|
|
azure_rm_networkinterface:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm001
|
|
virtual_network: testvm001
|
|
subnet: testvm001
|
|
public_ip_name: testvm001
|
|
security_group: testvm001
|
|
|
|
- name: Create virtual machine
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
vm_size: Standard_A0
|
|
storage_account: "{{ storage_account }}"
|
|
storage_container: testvm001
|
|
storage_blob: testvm001.vhd
|
|
admin_username: adminuser
|
|
admin_password: Password123!
|
|
short_hostname: testvm
|
|
os_type: Linux
|
|
network_interfaces: testvm001
|
|
availability_set: "avbs{{ resource_group | hash('md5') | truncate(7, True, '') }}"
|
|
image:
|
|
offer: UbuntuServer
|
|
publisher: Canonical
|
|
sku: 16.04-LTS
|
|
version: latest
|
|
register: output
|
|
|
|
- assert:
|
|
that:
|
|
- azure_vm.properties.availabilitySet.id
|
|
|
|
- name: Restart the virtual machine
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
restarted: yes
|
|
vm_size: Standard_A0
|
|
register: output
|
|
|
|
- assert:
|
|
that:
|
|
- "azure_vm.powerstate in ['starting', 'running']"
|
|
- output.changed
|
|
|
|
- name: Deallocate the virtual machine
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
allocated: no
|
|
vm_size: Standard_A0
|
|
register: output
|
|
|
|
- assert:
|
|
that:
|
|
- azure_vm.powerstate == 'deallocated'
|
|
- output.changed
|
|
|
|
- name: Start the virtual machine
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
vm_size: Standard_A0
|
|
register: output
|
|
|
|
- assert:
|
|
that:
|
|
- "azure_vm.powerstate in ['starting', 'running']"
|
|
- output.changed
|
|
|
|
- name: Should be idempotent
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
vm_size: Standard_A0
|
|
storage_account: "{{ storage_account }}"
|
|
storage_container: testvm001
|
|
storage_blob: testvm001.vhd
|
|
admin_username: adminuser
|
|
admin_password: Password123!
|
|
short_hostname: testvm
|
|
os_type: Linux
|
|
network_interfaces: testvm001
|
|
image:
|
|
offer: UbuntuServer
|
|
publisher: Canonical
|
|
sku: 16.04-LTS
|
|
version: latest
|
|
register: output
|
|
|
|
- assert:
|
|
that: not output.changed
|
|
|
|
- name: Delete VM
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
state: absent
|
|
vm_size: Standard_A0
|
|
register: output
|
|
|
|
- name: NIC should be gone
|
|
azure_rm_networkinterface_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm001
|
|
register: output
|
|
|
|
- assert:
|
|
that: azure_networkinterfaces | length == 0
|
|
|
|
- name: PIP should be gone
|
|
azure_rm_publicipaddress_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm001
|
|
register: output
|
|
|
|
- assert:
|
|
that: azure_publicipaddresses | length == 0
|
|
|
|
# TODO: Until we have a module to create/delete images this is the best tests
|
|
# I can do
|
|
- name: assert error thrown with invalid image dict
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
state: present
|
|
image:
|
|
offer: UbuntuServer
|
|
register: fail_invalid_image_dict
|
|
failed_when: 'fail_invalid_image_dict.msg != "parameter error: expecting image to contain [publisher, offer, sku, version] or [name, resource_group]"'
|
|
|
|
- name: assert error thrown with invalid image type
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
state: present
|
|
image:
|
|
- testing
|
|
register: fail_invalid_image_type
|
|
failed_when: 'fail_invalid_image_type.msg != "parameter error: expecting image to be a string or dict not list"'
|
|
|
|
- name: assert error finding missing custom image
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
state: present
|
|
image: invalid-image
|
|
register: fail_missing_custom_image
|
|
failed_when: fail_missing_custom_image.msg != "Error could not find image with name invalid-image"
|
|
|
|
- name: assert error finding missing custom image (dict style)
|
|
azure_rm_virtualmachine:
|
|
resource_group: "{{ resource_group }}"
|
|
name: testvm002
|
|
state: present
|
|
image:
|
|
name: invalid-image
|
|
register: fail_missing_custom_image_dict
|
|
failed_when: fail_missing_custom_image_dict.msg != "Error could not find image with name invalid-image" |