summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSam Doran <sdoran@redhat.com>2019-06-13 11:48:56 -0400
committerMatt Clay <matt@mystile.com>2019-06-13 08:48:55 -0700
commit99fd7821b31e065379773385f64a123f596b9ef5 (patch)
tree804acebc23f1c95f8d45b2a7d8ce7ee348553d43 /test
parentd2dc4c9bc43aae4e1b46098ac1e006fa3dda00ae (diff)
downloadansible-99fd7821b31e065379773385f64a123f596b9ef5.tar.gz
Split azure_rm_virtualmachine integration tests to prevent timeouts (#57250)
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/defaults/main.yml8
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/inventory.yml66
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/main.yml7
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/meta/main.yml2
-rwxr-xr-xtest/integration/targets/azure_rm_virtualmachine/runme.sh5
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_deallocate.yml90
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_dual_nic.yml131
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_invalid.yml35
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal.yml118
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_no_public_ip.yml41
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_public_ip.yml311
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/main.yml3
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/setup.yml82
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/teardown.yml62
-rw-r--r--test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml580
15 files changed, 821 insertions, 720 deletions
diff --git a/test/integration/targets/azure_rm_virtualmachine/defaults/main.yml b/test/integration/targets/azure_rm_virtualmachine/defaults/main.yml
deleted file mode 100644
index 1ce0ce4e53..0000000000
--- a/test/integration/targets/azure_rm_virtualmachine/defaults/main.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-ssh_keys:
- - path: '/home/chouseknecht/.ssh/authorized_keys'
- key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1igsIlcmTa/yfsJnTtnrEX7PP/a01gwbXcig6JOKyrUmJB8E6c/wtZwP115VSyDRTO6TEL/sBFUpkSw01zM8ydNATErh8meBlAlbnDq5NLhDXnMizgG0VNn0iLc/WplFTqkefsHXa8NtIxAtyEVIj/fKbK3XfBOdEpE3+MJYNtGlWyaod28W+5qmQPZDQys+YnE4OjSwN7D3g85/7dtLFvDH+lEC4ooJOaxVFr9VSMXUIkaRF6oI+R1Zu803LFSCTb4BfFOYOHPuQ/rEMP0KuUzggvP+TEBY14PEA2FoHOn+oRsT0ZR2+loGRaxSVqCQKaEHbNbkm+6Rllx2NQRO0BJxCSKRU1iifInLPxmSc4gvsHCKMAWy/tGkmKHPWIfN8hvwyDMK5MNBp/SJ1pVx4xuFDQjVWNbll0yk2+72uJgtFHHwEPK9QsOz45gX85vS3yhYCKrscS/W9h2l36SWwQXuGy4fXotE7esPsvNGAzBndHX1O8RMPg47qJXz059RyoGforoa9TnzIs3hIv+ts7ESx3OEq3HNk0FJ+wDka7IM7WQpGrVToJ0vfDy9Q46nw54vv5Zc/u4OZF3F5twHmyf3rLYKXRDuCvZQKT2iWQKVX6j63bq6orA5hwl22zndxWZNtOwtq8Sd0Ns0K/Fo/ggYDDGBtr68DwhA+MrxrHw== chouseknecht@ansible.com"
-image:
- offer: CentOS
- publisher: OpenLogic
- sku: '7.1'
- version: latest \ No newline at end of file
diff --git a/test/integration/targets/azure_rm_virtualmachine/inventory.yml b/test/integration/targets/azure_rm_virtualmachine/inventory.yml
new file mode 100644
index 0000000000..acd98ebf7f
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/inventory.yml
@@ -0,0 +1,66 @@
+all:
+ hosts:
+ azure_test_invalid:
+ azure_test_public_ip:
+ network: 10.42.0.0/24
+ subnet: 10.42.0.0/28
+
+ azure_test_no_public_ip:
+ network: 10.42.1.0/24
+ subnet: 10.42.1.0/28
+
+ azure_test_deallocate:
+ network: 10.42.2.0/24
+ subnet: 10.42.2.0/28
+
+ azure_test_minimal:
+ network: 10.42.3.0/24
+ subnet: 10.42.3.0/28
+
+ azure_test_dual_nic:
+ network: 10.42.4.0/24
+ subnet: 10.42.4.0/28
+ secondary_network: 10.42.5.0/24
+ secondary_subnet: 10.42.5.0/28
+ nic_list:
+ - name: "{{ 'int' ~ uid_short ~ '-1' }}"
+ resource_group: "{{ resource_group_secondary }}"
+ - name: "{{ 'int' ~ uid_short ~ '-2' }}"
+ resource_group: "{{ resource_group_secondary }}"
+
+ vars:
+ ansible_connection: local
+ ansible_python_interpreter: "{{ ansible_playbook_python }}"
+
+ uid: "{{ (resource_group ~ inventory_hostname) | hash('md5') | truncate(18, True, '') }}"
+ uid_short: "{{ (resource_group ~ inventory_hostname) | hash('md5') | truncate(10, True, '') }}"
+
+ storage_account: "{{ 'stor' ~ uid }}"
+ availability_set: "{{ 'avbs' ~ uid_short }}"
+ vm_name: "{{ 'vm' ~ uid_short }}"
+ network_name: "{{ 'vnet' ~ uid_short }}"
+ subnet_name: "{{ 'snet' ~ uid_short }}"
+ security_group: "{{ 'sg' ~ uid_short }}"
+ public_ip_name: "{{ 'ip' ~ uid_short }}"
+ interface_name: "{{ 'int' ~ uid_short }}"
+
+ ssh_keys:
+ - path: '/home/chouseknecht/.ssh/authorized_keys'
+ key_data: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC1igsIlcmTa/yfsJnTtnrEX7PP/a01gwbXcig6JOKyrUmJB8E6c/wtZwP115VSyDRTO6TEL/sBFUpkSw01zM8ydNATErh8meBlAlbnDq5NLhDXnMizgG0VNn0iLc/WplFTqkefsHXa8NtIxAtyEVIj/fKbK3XfBOdEpE3+MJYNtGlWyaod28W+5qmQPZDQys+YnE4OjSwN7D3g85/7dtLFvDH+lEC4ooJOaxVFr9VSMXUIkaRF6oI+R1Zu803LFSCTb4BfFOYOHPuQ/rEMP0KuUzggvP+TEBY14PEA2FoHOn+oRsT0ZR2+loGRaxSVqCQKaEHbNbkm+6Rllx2NQRO0BJxCSKRU1iifInLPxmSc4gvsHCKMAWy/tGkmKHPWIfN8hvwyDMK5MNBp/SJ1pVx4xuFDQjVWNbll0yk2+72uJgtFHHwEPK9QsOz45gX85vS3yhYCKrscS/W9h2l36SWwQXuGy4fXotE7esPsvNGAzBndHX1O8RMPg47qJXz059RyoGforoa9TnzIs3hIv+ts7ESx3OEq3HNk0FJ+wDka7IM7WQpGrVToJ0vfDy9Q46nw54vv5Zc/u4OZF3F5twHmyf3rLYKXRDuCvZQKT2iWQKVX6j63bq6orA5hwl22zndxWZNtOwtq8Sd0Ns0K/Fo/ggYDDGBtr68DwhA+MrxrHw== chouseknecht@ansible.com"
+
+ image:
+ offer: CentOS
+ publisher: OpenLogic
+ sku: '7.1'
+ version: latest
+
+ image_paid:
+ publisher: cognosys
+ offer: ubuntu-14-04-lts
+ sku: hardened-ubuntu-14-04
+ version: latest
+
+ plan_paid:
+ name: hardened-ubuntu-14-04
+ product: ubuntu-14-04-lts
+ publisher: cognosys
diff --git a/test/integration/targets/azure_rm_virtualmachine/main.yml b/test/integration/targets/azure_rm_virtualmachine/main.yml
new file mode 100644
index 0000000000..7722487bff
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/main.yml
@@ -0,0 +1,7 @@
+- name: Run Azurue VM tests in parallel
+ hosts: all
+ gather_facts: no
+ strategy: free
+ tasks:
+ - name: Include tasks based on inventory hostname
+ include_tasks: tasks/{{ inventory_hostname }}.yml
diff --git a/test/integration/targets/azure_rm_virtualmachine/meta/main.yml b/test/integration/targets/azure_rm_virtualmachine/meta/main.yml
deleted file mode 100644
index 95e1952f98..0000000000
--- a/test/integration/targets/azure_rm_virtualmachine/meta/main.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-dependencies:
- - setup_azure
diff --git a/test/integration/targets/azure_rm_virtualmachine/runme.sh b/test/integration/targets/azure_rm_virtualmachine/runme.sh
new file mode 100755
index 0000000000..c7895c9d26
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/runme.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -eux
+
+ansible-playbook -i inventory.yml main.yml "$@"
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_deallocate.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_deallocate.yml
new file mode 100644
index 0000000000..52fc0102e8
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_deallocate.yml
@@ -0,0 +1,90 @@
+- include_tasks: setup.yml
+
+- name: Create minimal VM with defaults
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ admin_username: "testuser"
+ admin_password: "Pass123$$$abx!"
+ vm_size: Standard_A0
+ virtual_network: "{{ network_name }}"
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ register: vm_output
+
+- name: Restart the virtual machine
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ restarted: yes
+ vm_size: Standard_A0
+ register: restart_result
+
+- name: Ensue VM was restarted
+ assert:
+ that:
+ - "azure_vm.powerstate in ['starting', 'running']"
+ - restart_result is changed
+
+- name: Deallocate the virtual machine
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ allocated: no
+ vm_size: Standard_A0
+ register: deallocate_result
+
+- name: Ensure VM was deallocated
+ assert:
+ that:
+ - azure_vm.powerstate == 'deallocated'
+ - deallocate_result is changed
+
+- name: Start the virtual machine
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ vm_size: Standard_A0
+ register: start_result
+
+- name: Ensure VM was started
+ assert:
+ that:
+ - "azure_vm.powerstate in ['starting', 'running']"
+ - start_result is changed
+
+- name: Delete VM
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ state: absent
+ remove_on_absent: all_autocreated
+
+- name: Destroy subnet
+ azure_rm_subnet:
+ resource_group: "{{ resource_group }}"
+ virtual_network: "{{ network_name }}"
+ name: "{{ subnet_name }}"
+ state: absent
+
+- name: Destroy virtual network
+ azure_rm_virtualnetwork:
+ resource_group: "{{ resource_group }}"
+ name: "{{ network_name }}"
+ state: absent
+
+- name: Destroy availability set
+ azure_rm_availabilityset:
+ resource_group: "{{ resource_group }}"
+ name: "{{ availability_set }}"
+ state: absent
+
+- name: Destroy storage account
+ azure_rm_storageaccount:
+ resource_group: "{{ resource_group }}"
+ name: "{{ storage_account }}"
+ force_delete_nonempty: yes
+ state: absent
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_dual_nic.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_dual_nic.yml
new file mode 100644
index 0000000000..a5bbbad9a2
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_dual_nic.yml
@@ -0,0 +1,131 @@
+- include_tasks: setup.yml
+
+- name: Create virtual network in secondary resource group
+ azure_rm_virtualnetwork:
+ resource_group: "{{ resource_group_secondary }}"
+ name: "{{ network_name ~ '-2' }}"
+ address_prefixes: "{{ secondary_network }}"
+ register: create_virt_net_result
+
+- name: Create subnet in secondary resource group
+ azure_rm_subnet:
+ resource_group: "{{ resource_group_secondary }}"
+ name: "{{ subnet_name ~ '-2' }}"
+ address_prefix: "{{ secondary_subnet }}"
+ virtual_network: "{{ network_name ~ '-2' }}"
+
+- name: Create NICs for dual NIC VM in secondary resource group
+ azure_rm_networkinterface:
+ resource_group: "{{ item.resource_group }}"
+ name: "{{ item.name }}"
+ virtual_network: "{{ network_name ~ '-2' }}"
+ subnet: "{{ subnet_name ~ '-2' }}"
+ loop: "{{ nic_list }}"
+
+- name: Create virtual machine with two NICs
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}" # Should this be resource_group_secondary?
+ name: "{{ vm_name }}"
+ vm_size: Standard_A0
+ storage_account: "{{ storage_account }}"
+ storage_container: "{{ vm_name }}"
+ storage_blob: "{{ vm_name }}.vhd"
+ admin_username: adminuser
+ admin_password: Password123!
+ short_hostname: testvm
+ os_type: Linux
+ os_disk_size_gb: 64
+ os_disk_name: testosdiskxx
+ network_interfaces: "{{ nic_list }}"
+ availability_set: "{{ availability_set }}"
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ tags:
+ abc: def
+
+- name: Ensure VM was created properly
+ assert:
+ that:
+ - azure_vm.properties.availabilitySet.id
+ - azure_vm.properties.storageProfile.osDisk.name == 'testosdiskxx'
+
+- name: Retrieve VM facts (filtering by name)
+ azure_rm_virtualmachine_facts:
+ resource_group: "{{ resource_group }}" # Should this be resource_group_secondary?
+ name: "{{ vm_name }}"
+ register: vm_facts_results
+
+- name: Ensure facts module returned the second VM
+ assert:
+ that:
+ - vm_facts_results.vms | length == 1
+ - vm_facts_results.vms[0].name == "{{ vm_name }}"
+ - vm_facts_results.vms[0].location
+ - vm_facts_results.vms[0].admin_username == 'adminuser'
+ - vm_facts_results.vms[0].resource_group == "{{ resource_group }}"
+ - vm_facts_results.vms[0].power_state != None
+
+- name: Retrieve facts by tags
+ azure_rm_virtualmachine_facts:
+ tags:
+ - abc:def
+ register: facts_by_tags_results
+
+- name: Assert that facts module returned the second VM
+ assert:
+ that:
+ - facts_by_tags_results.vms | length >= 1
+
+- name: Should be idempotent with a dual NICs
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}" # Should this be resource_group_secondary?
+ name: "{{ vm_name }}"
+ vm_size: Standard_A0
+ storage_account: "{{ storage_account }}"
+ storage_container: "{{ vm_name }}"
+ storage_blob: "{{ vm_name }}.vhd"
+ admin_username: adminuser
+ admin_password: Password123!
+ short_hostname: testvm
+ os_type: Linux
+ os_disk_size_gb: 64
+ network_interfaces: "{{ nic_list }}"
+ availability_set: "{{ availability_set }}"
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ register: dual_nics_result
+
+- name: Ensure nothing changed
+ assert:
+ that: dual_nics_result is not changed
+
+- name: Generalize VM
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}" # Should this be resource_group_secondary?
+ name: "{{ vm_name }}"
+ generalized: yes
+
+- name: Gather facts and check if machine is generalized
+ azure_rm_virtualmachine_facts:
+ resource_group: "{{ resource_group }}" # Should this be resource_group_secondary?
+ name: "{{ vm_name }}"
+ register: generalized_output
+
+- name: Ensure power state is generalized
+ assert:
+ that: generalized_output.vms[0].power_state == 'generalized'
+
+- name: Delete dual NIC VM
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}" # Should this be resource_group_secondary?
+ name: "{{ vm_name }}"
+ state: absent
+ vm_size: Standard_A0
+ async: 5000
+ poll: 0
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_invalid.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_invalid.yml
new file mode 100644
index 0000000000..3b362e7de6
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_invalid.yml
@@ -0,0 +1,35 @@
+# 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: "{{ vm_name }}"
+ 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: "{{ vm_name }}"
+ 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: "{{ vm_name }}"
+ 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: "{{ vm_name }}"
+ 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"
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal.yml
new file mode 100644
index 0000000000..d2a79082a9
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_minimal.yml
@@ -0,0 +1,118 @@
+- include_tasks: setup.yml
+
+# # Tests possible when CI user acccount setup with required authority
+# - name: Create virtual machine with image and plan which requires acceptance of terms
+# azure_rm_virtualmachine:
+# resource_group: "{{ resource_group }}"
+# name: testvm009
+# vm_size: Standard_A0
+# storage_account: "{{ storage_account }}"
+# storage_container: testvm001
+# storage_blob: testvm003.vhd
+# admin_username: adminuser
+# admin_password: Password123!
+# short_hostname: testvm
+# os_type: Linux
+# availability_set: "{{ availability_set }}"
+# image: "{{ image_paid }}"
+# plan_paid: "{{ plan_paid }}"
+# register: create_image_plan_result
+
+# - assert:
+# that:
+# - create_image_plan_result is changed
+# - create_image_plan_result.ansible_facts.azure_vm.properties.storageProfile.imageReference.publisher == image_paid.publisher
+
+# - name: Should be idempotent with image and plan which requires acceptance of terms
+# azure_rm_virtualmachine:
+# resource_group: "{{ resource_group }}"
+# name: testvm009
+# vm_size: Standard_A0
+# storage_account: "{{ storage_account }}"
+# storage_container: testvm001
+# storage_blob: testvm003.vhd
+# admin_username: adminuser
+# admin_password: Password123!
+# short_hostname: testvm
+# os_type: Linux
+# availability_set: "{{ availability_set }}"
+# image: "{{ image_paid }}"
+# plan_paid: "{{ plan_paid }}"
+# register: create_image_plan_again_result
+
+# - assert:
+# that: create_image_plan_again is not changed
+
+- name: Create minimal VM with defaults
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ admin_username: "testuser"
+ admin_password: "Pass123$$$abx!"
+ vm_size: Standard_B1ms
+ virtual_network: "{{ network_name }}"
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ register: vm_output
+
+- name: Delete VM
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ remove_on_absent: all_autocreated
+ state: absent
+
+- name: Query auto created NIC
+ azure_rm_networkinterface_facts:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}01"
+ register: nic_result
+
+- name: Query auto created security group
+ azure_rm_securitygroup_facts:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}01"
+ register: nsg_result
+
+- name: Query auto created public IP
+ azure_rm_publicipaddress_facts:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}01"
+ register: pip_result
+
+- name: Assert that autocreated resources were deleted
+ assert:
+ that:
+ # what about the default storage group?
+ - nic_result.ansible_facts.azure_networkinterfaces | length == 0
+ - nsg_result.ansible_facts.azure_securitygroups | length == 0
+ - pip_result.ansible_facts.azure_publicipaddresses | length == 0
+
+- name: Destroy subnet
+ azure_rm_subnet:
+ resource_group: "{{ resource_group }}"
+ virtual_network: "{{ network_name }}"
+ name: "{{ subnet_name }}"
+ state: absent
+
+- name: Destroy virtual network
+ azure_rm_virtualnetwork:
+ resource_group: "{{ resource_group }}"
+ name: "{{ network_name }}"
+ state: absent
+
+- name: Destroy availability set
+ azure_rm_availabilityset:
+ resource_group: "{{ resource_group }}"
+ name: "{{ availability_set }}"
+ state: absent
+
+- name: Destroy storage account
+ azure_rm_storageaccount:
+ resource_group: "{{ resource_group }}"
+ name: "{{ storage_account }}"
+ force_delete_nonempty: yes
+ state: absent
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_no_public_ip.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_no_public_ip.yml
new file mode 100644
index 0000000000..f06eea8524
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_no_public_ip.yml
@@ -0,0 +1,41 @@
+- include_tasks: setup.yml
+
+- name: Create virtual machine without public ip address and with boot diagnostics enabled
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ vm_size: Standard_A0
+ admin_username: adminuser
+ admin_password: Password123!
+ short_hostname: testvm
+ os_type: Linux
+ public_ip_allocation_method: Disabled
+ storage_account_name: "{{ storage_account }}"
+ availability_set: "{{ availability_set }}"
+ virtual_network: "{{ network_name }}"
+ boot_diagnostics:
+ enabled: yes
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ register: create_vm_public_result
+
+- name: Ensure VM was created properly
+ assert:
+ that:
+ - azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
+ - azure_vm.properties.diagnosticsProfile.bootDiagnostics.storageUri is defined
+ - azure_vm.properties.instanceView.bootDiagnostics.consoleScreenshotBlobUri is defined
+ - azure_vm.properties.instanceView.bootDiagnostics.serialConsoleLogBlobUri is defined
+ - not 'publicIPAddress' in create_vm_public_result.ansible_facts.azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties
+
+- name: Delete VM with no public ip
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ state: absent
+ remove_on_absent: all_autocreated
+ async: 5000
+ poll: 0
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_public_ip.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_public_ip.yml
new file mode 100644
index 0000000000..f25d944a78
--- /dev/null
+++ b/test/integration/targets/azure_rm_virtualmachine/tasks/azure_test_public_ip.yml
@@ -0,0 +1,311 @@
+- include_tasks: setup.yml
+
+- name: Create public ip
+ azure_rm_publicipaddress:
+ resource_group: "{{ resource_group }}"
+ allocation_method: Static
+ name: "{{ public_ip_name }}"
+
+- name: Create security group
+ azure_rm_securitygroup:
+ resource_group: "{{ resource_group }}"
+ name: "{{ security_group }}"
+ purge_rules: yes
+ rules:
+ - name: ALLOW_SSH
+ protocol: Tcp
+ destination_port_range: 22
+ access: Allow
+ priority: 100
+ direction: Inbound
+
+ - name: ALLOW_HTTP
+ protocol: Tcp
+ destination_port_range: 80
+ access: Allow
+ priority: 110
+ direction: Inbound
+
+- name: Create network interface
+ azure_rm_networkinterface:
+ resource_group: "{{ resource_group }}"
+ name: "{{ interface_name }}"
+ virtual_network: "{{ network_name }}"
+ subnet: "{{ subnet_name }}"
+ public_ip_name: "{{ public_ip_name }}"
+ security_group: "{{ security_group }}"
+
+- name: Create virtual machine with a single NIC and no boot diagnostics
+ register: output
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ vm_size: Standard_A0
+ storage_account: "{{ storage_account }}"
+ storage_container: "{{ vm_name }}"
+ storage_blob: "{{ vm_name }}.vhd"
+ admin_username: adminuser
+ admin_password: Password123!
+ short_hostname: testvm
+ os_type: Linux
+ network_interfaces: "{{ interface_name }}"
+ availability_set: "{{ availability_set }}"
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ custom_data: |
+ #!/bin/sh
+ echo "custom_data was executed" > /tmp/custom_data.txt
+
+- name: Ensure VM was created properly
+ assert:
+ that:
+ - azure_vm.properties.provisioningState == 'Succeeded'
+ - azure_vm.properties.availabilitySet.id
+ # initial response from creation has no diagnosticsProfile
+ # if you run it again however, there is one in the response
+ # so we handle both cases
+ - "'diagnosticsProfile' not in azure_vm.properties or not azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled"
+
+- name: Get facts for virtual machine without boot diagnostics disabled
+ azure_rm_virtualmachine_facts:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ register: vm_facts_no_boot_diag_result
+
+- name: Ensure VM facts are correct
+ assert:
+ that:
+ - vm_facts_no_boot_diag_result.vms != []
+ - not vm_facts_no_boot_diag_result.vms[0].boot_diagnostics.enabled
+ - not vm_facts_no_boot_diag_result.vms[0].boot_diagnostics.storage_uri
+
+- name: Enable boot diagnostics on an existing VM for the first time without specifying a storage account
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ boot_diagnostics:
+ enabled: yes
+ # without specifying storage_account you get a new default storage account for the VM
+
+- name: Ensure VM properties are correct
+ assert:
+ that:
+ - azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
+ - azure_vm.properties.diagnosticsProfile.bootDiagnostics.storageUri is defined
+ - azure_vm.properties.instanceView.bootDiagnostics.consoleScreenshotBlobUri is defined
+ - azure_vm.properties.instanceView.bootDiagnostics.serialConsoleLogBlobUri is defined
+
+- name: Get facts for virtual machine with boot diagnostics enabled
+ azure_rm_virtualmachine_facts:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ register: vm_facts_boot_diag_result
+
+- name: Ensure VM facts were returned
+ assert:
+ that:
+ - vm_facts_boot_diag_result.vms != []
+ - vm_facts_boot_diag_result.vms[0].boot_diagnostics.enabled
+ - vm_facts_boot_diag_result.vms[0].boot_diagnostics.storage_uri is defined
+ - vm_facts_boot_diag_result.vms[0].boot_diagnostics.console_screenshot_uri is defined
+ - vm_facts_boot_diag_result.vms[0].boot_diagnostics.serial_console_log_uri is defined
+
+- name: Change the boot diagnostics storage account while enabled
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ boot_diagnostics:
+ enabled: yes
+ storage_account: "{{ storage_account }}"
+ ignore_errors: yes
+
+- name: Disable boot diagnostics and change the storage account at the same time
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ boot_diagnostics:
+ enabled: no
+ storage_account: "{{ storage_account }}"
+
+- name: Ensure boot diagnostics was disabled
+ assert:
+ that:
+ - not azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
+
+- name: Re-enable boot diagnostics on an existing VM where it was previously configured
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ boot_diagnostics:
+ enabled: yes
+ register: reenable_boot_diag_result
+
+- name: Ensure boot diagnostics was reenabled
+ assert:
+ that:
+ - azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
+ - azure_vm.properties.diagnosticsProfile.bootDiagnostics.storageUri is defined
+ - azure_vm.properties.instanceView.bootDiagnostics.consoleScreenshotBlobUri is defined
+ - azure_vm.properties.instanceView.bootDiagnostics.serialConsoleLogBlobUri is defined
+
+# - add_host:
+# name: new_azure_vm
+# ansible_host: '{{ reenable_boot_diag_result.ansible_facts.azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}'
+# ansible_connection: paramiko # not guaranteed to have sshpass...
+# ansible_user: adminuser
+# ansible_password: Password123!
+# ansible_host_key_checking: no
+
+# - name: wait for SSH port to be open
+# wait_for:
+# host: '{{ hostvars["new_azure_vm"].ansible_host }}'
+# port: 22
+# timeout: 60
+# state: started
+
+# # TODO: figure out how to make this work under ansible-test with the coverage injector
+# - block:
+# - name: wait for host to answer on SSH
+# delegate_to: new_azure_vm
+# wait_for_connection:
+
+# - name: get content from custom_data script
+# raw: cat /tmp/custom_data.txt
+# register: custom_data_content
+
+# - name: assert contents
+# assert:
+# that: custom_data_content.stdout | regex_search('custom_data was executed')
+# delegate_to: new_azure_vm
+
+# # TODO: figure out how to make this work under ansible-test with the coverage injector
+# - name: wait for file/content created by custom_data script
+# delegate_to: new_azure_vm
+# vars:
+# ansible_python_interpreter: python
+# wait_for:
+# path: /tmp/custom_data.txt
+# search_regex: ^custom_data was executed$
+# timeout: 20
+
+- name: Should be idempotent with a single NIC
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ vm_size: Standard_A0
+ storage_account: "{{ storage_account }}"
+ storage_container: "{{ vm_name }}"
+ storage_blob: "{{ vm_name }}.vhd"
+ admin_username: adminuser
+ admin_password: Password123!
+ short_hostname: testvm
+ os_type: Linux
+ network_interfaces: "{{ interface_name }}"
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ register: single_nic_result
+
+- name: Ensure nothing changed
+ assert:
+ that: single_nic_result is not changed
+
+- name: Resize VM
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ vm_size: Standard_A1
+ storage_account: "{{ storage_account }}"
+ storage_container: "{{ vm_name }}"
+ storage_blob: "{{ vm_name }}.vhd"
+ admin_username: adminuser
+ admin_password: Password123!
+ short_hostname: testvm
+ os_type: Linux
+ network_interfaces: "{{ interface_name }}"
+ image:
+ offer: UbuntuServer
+ publisher: Canonical
+ sku: 16.04-LTS
+ version: latest
+ register: resize_result
+
+- name: Esure VM was resized
+ assert:
+ that:
+ - resize_result is changed
+ - resize_result.ansible_facts.azure_vm.properties.hardwareProfile.vmSize == "Standard_A1"
+
+- name: Delete VM
+ azure_rm_virtualmachine:
+ resource_group: "{{ resource_group }}"
+ name: "{{ vm_name }}"
+ state: absent
+ vm_size: Standard_A0
+
+- name: NIC should be gone
+ azure_rm_networkinterface_facts:
+ resource_group: "{{ resource_group }}"
+ name: "{{ interface_name }}"
+
+- name: Ensure NIC was removed
+ assert:
+ that: azure_networkinterfaces | length == 0
+
+- name: Public IP should be gone
+ azure_rm_publicipaddress_facts:
+ resource_group: "{{ resource_group }}"
+ name: "{{ public_ip_name }}"
+
+- name: Ensure public IP was removed
+ assert:
+ that: azure_publicipaddresses | length == 0
+
+- name: Destroy NIC
+ azure_rm_networkinterface:
+ resource_group: "{{ resource_group }}"
+ name: "{{ interface_name }}"
+ state: absent
+
+- name: Destroy security group
+ azure_rm_securitygroup:
+ resource_group: "{{ resource_group }}"
+ name: "{{ security_group }}"
+ state: absent
+
+- name: Destroy subnet
+ azure_rm_subnet:
+ resource_group: "{{ resource_group }}"
+ virtual_network: "{{ network_name }}"
+ name: "{{ subnet_name }}"
+ state: absent
+
+- name: Destroy virtual network
+ azure_rm_virtualnetwork:
+ resource_group: "{{ resource_group }}"
+ name: "{{ network_name }}"
+ state: absent
+
+- name: Destroy public ip
+ azure_rm_publicipaddress:
+ resource_group: "{{ resource_group }}"
+ name: "{{ public_ip_name }}"
+ state: absent
+
+- name: Destroy availability set
+ azure_rm_availabilityset:
+ resource_group: "{{ resource_group }}"
+ name: "{{ availability_set }}"
+ state: absent
+
+- name: Destroy storage account
+ azure_rm_storageaccount:
+ resource_group: "{{ resource_group }}"
+ name: "{{ storage_account }}"
+ force_delete_nonempty: true
+ state: absent
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/main.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/main.yml
deleted file mode 100644
index e549ec3ac0..0000000000
--- a/test/integration/targets/azure_rm_virtualmachine/tasks/main.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-- include: setup.yml
-- include: virtualmachine.yml
-- include: teardown.yml
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/setup.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/setup.yml
index 493f0a14ca..f053cac03d 100644
--- a/test/integration/targets/azure_rm_virtualmachine/tasks/setup.yml
+++ b/test/integration/targets/azure_rm_virtualmachine/tasks/setup.yml
@@ -1,74 +1,26 @@
-- name: Create random names
- set_fact:
- storage_account: "{{ resource_group | hash('md5') | truncate(24, True, '') }}"
- storage_account2: "{{ resource_group | hash('md5') | truncate(18, True, '') }}"
- vm_name1: "vm1{{ resource_group | hash('md5') | truncate(5, True, '') }}"
- vm_name2: "vm2{{ resource_group | hash('md5') | truncate(5, True, '') }}"
- vm_name3: "vm3{{ resource_group | hash('md5') | truncate(5, True, '') }}"
- vm_name4: "vm4{{ resource_group | hash('md5') | truncate(5, True, '') }}"
- abs_name1: "avbs1{{ resource_group | hash('md5') | truncate(3, True, '') }}"
- abs_name2: "avbs2{{ resource_group | hash('md5') | truncate(3, True, '') }}"
+- debug:
+ msg: "UID is {{ uid_short }}"
-- name: Create storage account
+- name: SETUP | Create storage account
azure_rm_storageaccount:
- resource_group: "{{ resource_group }}"
- name: "{{ storage_account }}"
- account_type: Standard_LRS
-
-- name: Create 2nd storage account
- azure_rm_storageaccount:
- resource_group: "{{ resource_group }}"
- name: "{{ storage_account2 }}"
- account_type: Standard_LRS
+ resource_group: "{{ resource_group }}"
+ name: "{{ storage_account }}"
+ account_type: Standard_LRS
-- name: Create an availability set
+- name: SETUP | Create availability set
azure_rm_availabilityset:
- name: "{{ abs_name1 }}"
+ name: "{{ availability_set }}"
resource_group: "{{ resource_group }}"
-- name: Create virtual network
+- name: SETUP | Create virtual network
azure_rm_virtualnetwork:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- address_prefixes: "10.10.0.0/16"
+ resource_group: "{{ resource_group }}"
+ name: "{{ network_name }}"
+ address_prefixes: "{{ network }}"
-- name: Add subnet
+- name: SETUP | Create subnet
azure_rm_subnet:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- address_prefix: "10.10.0.0/24"
- virtual_network: "{{ vm_name1 }}"
-
-- name: Create public ip
- azure_rm_publicipaddress:
- resource_group: "{{ resource_group }}"
- allocation_method: Static
- name: "{{ vm_name1 }}"
-
-- name: Create security group
- azure_rm_securitygroup:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- purge_rules: yes
- rules:
- - name: ALLOW_SSH
- protocol: Tcp
- destination_port_range: 22
- access: Allow
- priority: 100
- direction: Inbound
- - name: ALLOW_HTTP
- protocol: Tcp
- destination_port_range: 80
- access: Allow
- priority: 110
- direction: Inbound
-
-- name: Create NIC for single nic VM
- azure_rm_networkinterface:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- virtual_network: "{{ vm_name1 }}"
- subnet: "{{ vm_name1 }}"
- public_ip_name: "{{ vm_name1 }}"
- security_group: "{{ vm_name1 }}"
+ resource_group: "{{ resource_group }}"
+ name: "{{ subnet_name }}"
+ address_prefix: "{{ subnet }}"
+ virtual_network: "{{ network_name }}"
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/teardown.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/teardown.yml
deleted file mode 100644
index 08b1cacc65..0000000000
--- a/test/integration/targets/azure_rm_virtualmachine/tasks/teardown.yml
+++ /dev/null
@@ -1,62 +0,0 @@
-- name: Destroy NIC for single nic VM
- azure_rm_networkinterface:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- state: absent
-
-- name: Destroy 2nd security group
- azure_rm_securitygroup:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name2 }}"
- state: absent
-
-- name: Destroy security group
- azure_rm_securitygroup:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- state: absent
-
-- name: Destroy subnet
- azure_rm_subnet:
- resource_group: "{{ resource_group }}"
- virtual_network: "{{ vm_name1 }}"
- name: "{{ vm_name1 }}"
- state: absent
-
-- name: Destroy virtual network
- azure_rm_virtualnetwork:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- state: absent
-
-- name: Destroy public ip
- azure_rm_publicipaddress:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- state: absent
-
-- name: Destroy 2nd availability set
- azure_rm_availabilityset:
- resource_group: "{{ resource_group }}"
- name: "{{ abs_name2 }}"
- state: absent
-
-- name: Destroy an availability set
- azure_rm_availabilityset:
- resource_group: "{{ resource_group }}"
- name: "{{ abs_name1 }}"
- state: absent
-
-- name: Destroy 2nd storage account
- azure_rm_storageaccount:
- resource_group: "{{ resource_group }}"
- name: "{{ storage_account2 }}"
- force_delete_nonempty: true
- state: absent
-
-- name: Destroy storage account
- azure_rm_storageaccount:
- resource_group: "{{ resource_group }}"
- name: "{{ storage_account }}"
- force_delete_nonempty: true
- state: absent
diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml
deleted file mode 100644
index 9ee36ca869..0000000000
--- a/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml
+++ /dev/null
@@ -1,580 +0,0 @@
-- name: Create virtual machine with a single NIC and no boot diagnostics
- register: output
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- vm_size: Standard_A0
- storage_account: "{{ storage_account }}"
- storage_container: "{{ vm_name1 }}"
- storage_blob: "{{ vm_name1 }}.vhd"
- admin_username: adminuser
- admin_password: Password123!
- short_hostname: testvm
- os_type: Linux
- network_interfaces: "{{ vm_name1 }}"
- availability_set: "{{ abs_name1 }}"
- image:
- offer: UbuntuServer
- publisher: Canonical
- sku: 16.04-LTS
- version: latest
- custom_data: |
- #!/bin/sh
- echo "custom_data was executed" > /tmp/custom_data.txt
-
-- assert:
- that:
- - azure_vm.properties.provisioningState == 'Succeeded'
- - azure_vm.properties.availabilitySet.id
- # initial response from creation has no diagnosticsProfile
- # if you run it again however, there is one in the response
- # so we handle both cases
- - "'diagnosticsProfile' not in azure_vm.properties or not azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled"
-
-- name: Get facts for virtual machine without boot diagnostics disabled
- azure_rm_virtualmachine_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- register: output
-
-- assert:
- that:
- - output.vms != []
- - not output.vms[0].boot_diagnostics.enabled
- - not output.vms[0].boot_diagnostics.storage_uri
-
-- name: Enable boot diagnostics on an existing VM for the first time without specifying a storage account
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- boot_diagnostics:
- enabled: true
- # without specifying storage_account you get a new default storage account for the VM
- register: output
-
-- assert:
- that:
- - azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
- - azure_vm.properties.diagnosticsProfile.bootDiagnostics.storageUri is defined
- - azure_vm.properties.instanceView.bootDiagnostics.consoleScreenshotBlobUri is defined
- - azure_vm.properties.instanceView.bootDiagnostics.serialConsoleLogBlobUri is defined
-
-- name: Get facts for virtual machine with boot diagnostics enabled
- azure_rm_virtualmachine_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- register: output
-
-- assert:
- that:
- - output.vms != []
- - output.vms[0].boot_diagnostics.enabled
- - output.vms[0].boot_diagnostics.storage_uri is defined
- - output.vms[0].boot_diagnostics.console_screenshot_uri is defined
- - output.vms[0].boot_diagnostics.serial_console_log_uri is defined
-
-- name: Change the boot diagnostics storage account while enabled
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- boot_diagnostics:
- enabled: true
- storage_account: "{{ storage_account2 }}"
- ignore_errors: true
- register: output
-
-- name: Disable boot diagnostics and change the storage account at the same time
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- boot_diagnostics:
- enabled: false
- storage_account: "{{ storage_account }}"
- register: output
-
-- assert:
- that:
- - not azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
-
-- name: Re-enable boot diagnostics on an existing VM where it was previously configured
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- boot_diagnostics:
- enabled: true
- register: output
-
-- assert:
- that:
- - azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
- - azure_vm.properties.diagnosticsProfile.bootDiagnostics.storageUri is defined
- - azure_vm.properties.instanceView.bootDiagnostics.consoleScreenshotBlobUri is defined
- - azure_vm.properties.instanceView.bootDiagnostics.serialConsoleLogBlobUri is defined
-
-# - add_host:
-# name: new_azure_vm
-# ansible_host: '{{ output.ansible_facts.azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}'
-# ansible_connection: paramiko # not guaranteed to have sshpass...
-# ansible_user: adminuser
-# ansible_password: Password123!
-# ansible_host_key_checking: false
-
-# - name: wait for SSH port to be open
-# wait_for:
-# host: '{{ hostvars["new_azure_vm"].ansible_host }}'
-# port: 22
-# timeout: 60
-# state: started
-
-#- block:
-# TODO: figure out how to make this work under ansible-test with the coverage injector
-# - name: wait for host to answer on SSH
-# delegate_to: new_azure_vm
-# wait_for_connection:
-# - name: get content from custom_data script
-# raw: cat /tmp/custom_data.txt
-# register: custom_data_content
-
-# - name: assert contents
-# assert:
-# that: custom_data_content.stdout | regex_search('custom_data was executed')
-# delegate_to: new_azure_vm
-
-# TODO: figure out how to make this work under ansible-test with the coverage injector
-# - name: wait for file/content created by custom_data script
-# delegate_to: new_azure_vm
-# vars:
-# ansible_python_interpreter: python
-# wait_for:
-# path: /tmp/custom_data.txt
-# search_regex: ^custom_data was executed$
-# timeout: 20
-
-- name: Restart the virtual machine
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- 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: "{{ vm_name1 }}"
- 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: "{{ vm_name1 }}"
- vm_size: Standard_A0
- register: output
-
-- assert:
- that:
- - "azure_vm.powerstate in ['starting', 'running']"
- - output.changed
-
-- name: Should be idempotent with a single NIC
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- vm_size: Standard_A0
- storage_account: "{{ storage_account }}"
- storage_container: "{{ vm_name1 }}"
- storage_blob: "{{ vm_name1 }}.vhd"
- admin_username: adminuser
- admin_password: Password123!
- short_hostname: testvm
- os_type: Linux
- network_interfaces: "{{ vm_name1 }}"
- image:
- offer: UbuntuServer
- publisher: Canonical
- sku: 16.04-LTS
- version: latest
- register: output
-
-- assert:
- that: not output.changed
-
-- name: Resize VM
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- vm_size: Standard_A1
- storage_account: "{{ storage_account }}"
- storage_container: "{{ vm_name1 }}"
- storage_blob: "{{ vm_name1 }}.vhd"
- admin_username: adminuser
- admin_password: Password123!
- short_hostname: testvm
- os_type: Linux
- network_interfaces: "{{ vm_name1 }}"
- image:
- offer: UbuntuServer
- publisher: Canonical
- sku: 16.04-LTS
- version: latest
- register: output
-
-- assert:
- that:
- - output.changed
- - output.ansible_facts.azure_vm.properties.hardwareProfile.vmSize == "Standard_A1"
-
-- name: Delete VM
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- state: absent
- vm_size: Standard_A0
- register: output
-
-- name: NIC should be gone
- azure_rm_networkinterface_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- register: output
-
-- assert:
- that: azure_networkinterfaces | length == 0
-
-- name: PIP should be gone
- azure_rm_publicipaddress_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name1 }}"
- register: output
-
-- assert:
- that: azure_publicipaddresses | length == 0
-
-- name: Create virtual machine without public ip address and with boot diagnostics enabled
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: testvmnoip
- vm_size: Standard_A0
- admin_username: adminuser
- admin_password: Password123!
- short_hostname: testvm
- os_type: Linux
- public_ip_allocation_method: Disabled
- availability_set: "{{ abs_name1 }}"
- boot_diagnostics:
- enabled: true
- image:
- offer: UbuntuServer
- publisher: Canonical
- sku: 16.04-LTS
- version: latest
- register: output
-
-- assert:
- that:
- - azure_vm.properties.diagnosticsProfile.bootDiagnostics.enabled
- - azure_vm.properties.diagnosticsProfile.bootDiagnostics.storageUri is defined
- - azure_vm.properties.instanceView.bootDiagnostics.consoleScreenshotBlobUri is defined
- - azure_vm.properties.instanceView.bootDiagnostics.serialConsoleLogBlobUri is defined
- - not 'publicIPAddress' in output.ansible_facts.azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties
-
-- name: Delete VM with no public ip
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: testvmnoip
- state: absent
- remove_on_absent: all_autocreated
- vm_size: Standard_A0
- async: 5000
- poll: 0
-
-- set_fact:
- niclist:
- - name: testnic011
- resource_group: "{{ resource_group_secondary }}"
- - name: testnic012
- resource_group: "{{ resource_group_secondary }}"
-
-- name: Create an availability set
- azure_rm_availabilityset:
- name: "{{ abs_name2 }}"
- resource_group: "{{ resource_group }}"
-
-- name: Create virtual network
- azure_rm_virtualnetwork:
- resource_group: "{{ resource_group_secondary }}"
- name: "{{ vm_name2 }}"
- address_prefixes: "10.10.0.0/16"
- register: vn
-
-- name: Add subnet
- azure_rm_subnet:
- resource_group: "{{ resource_group_secondary }}"
- name: "{{ vm_name2 }}"
- address_prefix: "10.10.0.0/24"
- virtual_network: "{{ vm_name2 }}"
-
-- name: Create NICs for dual nic VM
- azure_rm_networkinterface:
- resource_group: "{{ item.resource_group }}"
- name: "{{ item.name }}"
- virtual_network: "{{ vn.state.id }}"
- subnet: "{{ vm_name2 }}"
- security_group: "{{ vm_name2 }}"
- loop: "{{ niclist }}"
-
-- name: Create virtual machine with two NICs
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name2 }}"
- vm_size: Standard_A0
- storage_account: "{{ storage_account }}"
- storage_container: "{{ vm_name2 }}"
- storage_blob: "{{ vm_name2 }}.vhd"
- admin_username: adminuser
- admin_password: Password123!
- short_hostname: testvm
- os_type: Linux
- os_disk_size_gb: 64
- os_disk_name: testosdiskxx
- network_interfaces: "{{ niclist }}"
- availability_set: "{{ abs_name2 }}"
- image:
- offer: UbuntuServer
- publisher: Canonical
- sku: 16.04-LTS
- version: latest
- tags:
- abc: def
- register: output
-
-- assert:
- that:
- - azure_vm.properties.availabilitySet.id
- - azure_vm.properties.storageProfile.osDisk.name == 'testosdiskxx'
-
-- name: Retrieve vms facts (filtering by name)
- azure_rm_virtualmachine_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name2 }}"
- register: results
-
-- name: Assert that facts module returned the second vm
- assert:
- that:
- - results.vms | length == 1
- - results.vms[0].name == "{{ vm_name2 }}"
- - results.vms[0].location
- - results.vms[0].admin_username == 'adminuser'
- - results.vms[0].resource_group == "{{ resource_group }}"
- - results.vms[0].power_state != None
-
-- name: Retrieve facts by tags
- azure_rm_virtualmachine_facts:
- tags:
- - abc:def
- register: results
-
-- name: Assert that facts module returned the second vm
- assert:
- that:
- - results.vms | length >= 1
-
-- name: Should be idempotent with a dual NICs
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name2 }}"
- vm_size: Standard_A0
- storage_account: "{{ storage_account }}"
- storage_container: "{{ vm_name2 }}"
- storage_blob: "{{ vm_name2 }}.vhd"
- admin_username: adminuser
- admin_password: Password123!
- short_hostname: testvm
- os_type: Linux
- os_disk_size_gb: 64
- network_interfaces: "{{ niclist }}"
- availability_set: "{{ abs_name2 }}"
- image:
- offer: UbuntuServer
- publisher: Canonical
- sku: 16.04-LTS
- version: latest
- register: output
-
-- assert:
- that: not output.changed
-
-- name: Generalize VM
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name2 }}"
- generalized: yes
-
-- name: Gather facts and check if machine is generalized
- azure_rm_virtualmachine_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name2 }}"
- register: generalized_output
-
-- assert:
- that: generalized_output.vms[0].power_state == 'generalized'
-
-- name: Delete dual NIC VM
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name2 }}"
- state: absent
- vm_size: Standard_A0
- async: 5000
- poll: 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
- 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
- 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
- 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
- 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"
-
-## Tests possible when CI user acccount setup with required authority
-#- name: Set test facts
- #set_fact:
- #image_paid:
- #publisher: cognosys
- #offer: ubuntu-14-04-lts
- #sku: hardened-ubuntu-14-04
- #version: latest
- #plan_paid:
- #name: hardened-ubuntu-14-04
- #product: ubuntu-14-04-lts
- #publisher: cognosys
-
-#- name: Create virtual machine with image and plan which requires acceptance of terms
- #azure_rm_virtualmachine:
- #resource_group: "{{ resource_group }}"
- #name: testvm009
- #vm_size: Standard_A0
- #storage_account: "{{ storage_account }}"
- #storage_container: testvm001
- #storage_blob: testvm003.vhd
- #admin_username: adminuser
- #admin_password: Password123!
- #short_hostname: testvm
- #os_type: Linux
- #availability_set: "avbs{{ resource_group | hash('md5') | truncate(7, True, '') }}"
- #image: "{{ image_paid }}"
- #plan_paid: "{{ plan_paid }}"
- #register: output
-
-#- assert:
- #that:
- #- output.changed
- #- output.ansible_facts.azure_vm.properties.storageProfile.imageReference.publisher == image_paid.publisher
-
-#- name: Should be idempotent with image and plan which requires acceptance of terms
- #azure_rm_virtualmachine:
- #resource_group: "{{ resource_group }}"
- #name: testvm009
- #vm_size: Standard_A0
- #storage_account: "{{ storage_account }}"
- #storage_container: testvm001
- #storage_blob: testvm003.vhd
- #admin_username: adminuser
- #admin_password: Password123!
- #short_hostname: testvm
- #os_type: Linux
- #availability_set: "avbs{{ resource_group | hash('md5') | truncate(7, True, '') }}"
- #image: "{{ image_paid }}"
- #plan_paid: "{{ plan_paid }}"
-
-#- assert:
- #that: not output.changed
-
-- name: Create minimal VM with defaults
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name3 }}"
- admin_username: "testuser"
- admin_password: "Pass123$$$abx!"
- vm_size: Standard_B1ms
- image:
- offer: UbuntuServer
- publisher: Canonical
- sku: 16.04-LTS
- version: latest
- register: vm_output
-
-- name: Delete VM
- azure_rm_virtualmachine:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name3 }}"
- remove_on_absent: all_autocreated
- state: absent
-
-- name: Query NIC
- azure_rm_networkinterface_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name3 }}01"
- register: output_nic
-
-- name: Query NSG
- azure_rm_securitygroup_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name3 }}01"
- register: output_nsg
-
-- name: Query PIP
- azure_rm_publicipaddress_facts:
- resource_group: "{{ resource_group }}"
- name: "{{ vm_name3 }}01"
- register: output_pip
-
-- name: Assert that autocreated resources were deleted
- assert:
- that:
- # what about the default storage group?
- - output_nic.ansible_facts.azure_networkinterfaces | length == 0
- - output_nsg.ansible_facts.azure_securitygroups | length == 0
- - output_pip.ansible_facts.azure_publicipaddresses | length == 0