2019-05-14 21:06:07 +02:00
|
|
|
- name: Create virtual machine with a single NIC and no boot diagnostics
|
2018-01-17 06:05:35 +01:00
|
|
|
register: output
|
2017-08-12 01:16:39 +02:00
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
vm_size: Standard_A0
|
|
|
|
storage_account: "{{ storage_account }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
storage_container: "{{ vm_name1 }}"
|
|
|
|
storage_blob: "{{ vm_name1 }}.vhd"
|
2017-08-12 01:16:39 +02:00
|
|
|
admin_username: adminuser
|
|
|
|
admin_password: Password123!
|
|
|
|
short_hostname: testvm
|
|
|
|
os_type: Linux
|
2018-08-31 06:14:55 +02:00
|
|
|
network_interfaces: "{{ vm_name1 }}"
|
|
|
|
availability_set: "{{ abs_name1 }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
image:
|
|
|
|
offer: UbuntuServer
|
|
|
|
publisher: Canonical
|
|
|
|
sku: 16.04-LTS
|
|
|
|
version: latest
|
2018-01-17 06:05:35 +01:00
|
|
|
custom_data: |
|
|
|
|
#!/bin/sh
|
|
|
|
echo "custom_data was executed" > /tmp/custom_data.txt
|
2017-08-12 01:16:39 +02:00
|
|
|
|
2017-11-23 05:53:53 +01:00
|
|
|
- assert:
|
|
|
|
that:
|
2019-05-14 21:06:07 +02:00
|
|
|
- azure_vm.properties.provisioningState == 'Succeeded'
|
2017-11-23 05:53:53 +01:00
|
|
|
- azure_vm.properties.availabilitySet.id
|
2019-05-14 21:06:07 +02:00
|
|
|
# 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
|
2017-11-23 05:53:53 +01:00
|
|
|
|
2018-08-31 06:14:55 +02:00
|
|
|
# - 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
|
2018-01-17 06:05:35 +01:00
|
|
|
|
2018-08-01 04:23:50 +02:00
|
|
|
#- 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
|
2018-01-17 06:05:35 +01:00
|
|
|
|
2017-08-12 01:16:39 +02:00
|
|
|
- name: Restart the virtual machine
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
restarted: yes
|
2017-08-12 10:03:42 +02:00
|
|
|
vm_size: Standard_A0
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "azure_vm.powerstate in ['starting', 'running']"
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Deallocate the virtual machine
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
allocated: no
|
2017-08-12 10:03:42 +02:00
|
|
|
vm_size: Standard_A0
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- azure_vm.powerstate == 'deallocated'
|
|
|
|
- output.changed
|
|
|
|
|
|
|
|
- name: Start the virtual machine
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
vm_size: Standard_A0
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "azure_vm.powerstate in ['starting', 'running']"
|
|
|
|
- output.changed
|
|
|
|
|
2018-04-26 08:16:25 +02:00
|
|
|
- name: Should be idempotent with a single NIC
|
2017-08-12 01:16:39 +02:00
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
vm_size: Standard_A0
|
|
|
|
storage_account: "{{ storage_account }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
storage_container: "{{ vm_name1 }}"
|
|
|
|
storage_blob: "{{ vm_name1 }}.vhd"
|
2017-08-12 01:16:39 +02:00
|
|
|
admin_username: adminuser
|
|
|
|
admin_password: Password123!
|
|
|
|
short_hostname: testvm
|
|
|
|
os_type: Linux
|
2018-08-31 06:14:55 +02:00
|
|
|
network_interfaces: "{{ vm_name1 }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
image:
|
|
|
|
offer: UbuntuServer
|
|
|
|
publisher: Canonical
|
|
|
|
sku: 16.04-LTS
|
|
|
|
version: latest
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
2018-09-04 03:41:41 +02:00
|
|
|
- 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"
|
|
|
|
|
2017-08-12 01:16:39 +02:00
|
|
|
- name: Delete VM
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
state: absent
|
2017-08-12 10:03:42 +02:00
|
|
|
vm_size: Standard_A0
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: NIC should be gone
|
|
|
|
azure_rm_networkinterface_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_networkinterfaces | length == 0
|
|
|
|
|
|
|
|
- name: PIP should be gone
|
|
|
|
azure_rm_publicipaddress_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name1 }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_publicipaddresses | length == 0
|
2017-11-10 00:48:14 +01:00
|
|
|
|
2019-05-14 21:06:07 +02:00
|
|
|
- name: Create virtual machine without public ip address and with boot diagnostics enabled
|
2018-03-22 00:30:42 +01:00
|
|
|
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
|
2018-08-31 06:14:55 +02:00
|
|
|
availability_set: "{{ abs_name1 }}"
|
2019-05-14 21:06:07 +02:00
|
|
|
boot_diagnostics:
|
|
|
|
enabled: true
|
2018-03-22 00:30:42 +01:00
|
|
|
image:
|
|
|
|
offer: UbuntuServer
|
|
|
|
publisher: Canonical
|
|
|
|
sku: 16.04-LTS
|
|
|
|
version: latest
|
2019-05-14 21:06:07 +02:00
|
|
|
register: output
|
2018-03-22 00:30:42 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
2019-05-14 21:06:07 +02:00
|
|
|
- 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
|
2018-03-22 00:30:42 +01:00
|
|
|
- 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
|
2019-05-14 21:06:07 +02:00
|
|
|
remove_on_absent: all_autocreated
|
2018-03-22 00:30:42 +01:00
|
|
|
vm_size: Standard_A0
|
2018-08-31 06:14:55 +02:00
|
|
|
async: 5000
|
|
|
|
poll: 0
|
2018-03-22 00:30:42 +01:00
|
|
|
|
2018-08-01 04:52:21 +02:00
|
|
|
- set_fact:
|
|
|
|
niclist:
|
2018-08-31 06:14:55 +02:00
|
|
|
- name: testnic011
|
2018-08-01 04:52:21 +02:00
|
|
|
resource_group: "{{ resource_group_secondary }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
- name: testnic012
|
2019-05-14 21:06:07 +02:00
|
|
|
resource_group: "{{ resource_group_secondary }}"
|
2018-08-01 04:52:21 +02:00
|
|
|
|
2018-08-31 06:14:55 +02:00
|
|
|
- name: Create an availability set
|
|
|
|
azure_rm_availabilityset:
|
|
|
|
name: "{{ abs_name2 }}"
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
|
2018-08-01 04:52:21 +02:00
|
|
|
- name: Create virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
|
|
|
resource_group: "{{ resource_group_secondary }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name2 }}"
|
2018-08-01 04:52:21 +02:00
|
|
|
address_prefixes: "10.10.0.0/16"
|
|
|
|
register: vn
|
|
|
|
|
|
|
|
- name: Add subnet
|
|
|
|
azure_rm_subnet:
|
|
|
|
resource_group: "{{ resource_group_secondary }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name2 }}"
|
2018-08-01 04:52:21 +02:00
|
|
|
address_prefix: "10.10.0.0/24"
|
2018-08-31 06:14:55 +02:00
|
|
|
virtual_network: "{{ vm_name2 }}"
|
2018-08-01 04:52:21 +02:00
|
|
|
|
2018-04-26 08:16:25 +02:00
|
|
|
- name: Create NICs for dual nic VM
|
|
|
|
azure_rm_networkinterface:
|
2018-08-01 04:52:21 +02:00
|
|
|
resource_group: "{{ item.resource_group }}"
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
virtual_network: "{{ vn.state.id }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
subnet: "{{ vm_name2 }}"
|
2019-05-14 21:06:07 +02:00
|
|
|
security_group: "{{ vm_name2 }}"
|
2018-08-01 04:52:21 +02:00
|
|
|
loop: "{{ niclist }}"
|
2018-04-26 08:16:25 +02:00
|
|
|
|
|
|
|
- name: Create virtual machine with two NICs
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name2 }}"
|
2018-04-26 08:16:25 +02:00
|
|
|
vm_size: Standard_A0
|
|
|
|
storage_account: "{{ storage_account }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
storage_container: "{{ vm_name2 }}"
|
|
|
|
storage_blob: "{{ vm_name2 }}.vhd"
|
2018-04-26 08:16:25 +02:00
|
|
|
admin_username: adminuser
|
|
|
|
admin_password: Password123!
|
|
|
|
short_hostname: testvm
|
|
|
|
os_type: Linux
|
2018-08-23 09:36:58 +02:00
|
|
|
os_disk_size_gb: 64
|
2018-09-20 01:51:37 +02:00
|
|
|
os_disk_name: testosdiskxx
|
2018-04-26 08:16:25 +02:00
|
|
|
network_interfaces: "{{ niclist }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
availability_set: "{{ abs_name2 }}"
|
2018-04-26 08:16:25 +02:00
|
|
|
image:
|
|
|
|
offer: UbuntuServer
|
|
|
|
publisher: Canonical
|
|
|
|
sku: 16.04-LTS
|
|
|
|
version: latest
|
2019-03-21 08:53:44 +01:00
|
|
|
tags:
|
|
|
|
abc: def
|
2019-05-14 21:06:07 +02:00
|
|
|
register: output
|
|
|
|
|
2018-04-26 08:16:25 +02:00
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- azure_vm.properties.availabilitySet.id
|
2018-09-20 01:51:37 +02:00
|
|
|
- azure_vm.properties.storageProfile.osDisk.name == 'testosdiskxx'
|
2018-04-26 08:16:25 +02:00
|
|
|
|
2018-08-01 04:23:50 +02:00
|
|
|
- name: Retrieve vms facts (filtering by name)
|
|
|
|
azure_rm_virtualmachine_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name2 }}"
|
2018-08-01 04:23:50 +02:00
|
|
|
register: results
|
|
|
|
|
|
|
|
- name: Assert that facts module returned the second vm
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- results.vms | length == 1
|
2018-08-31 06:14:55 +02:00
|
|
|
- results.vms[0].name == "{{ vm_name2 }}"
|
2019-05-14 21:06:07 +02:00
|
|
|
- results.vms[0].location
|
2018-08-01 04:23:50 +02:00
|
|
|
- results.vms[0].admin_username == 'adminuser'
|
2018-09-04 05:25:01 +02:00
|
|
|
- results.vms[0].resource_group == "{{ resource_group }}"
|
|
|
|
- results.vms[0].power_state != None
|
2018-08-01 04:23:50 +02:00
|
|
|
|
2019-03-21 08:53:44 +01:00
|
|
|
- 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
|
|
|
|
|
2018-04-26 08:16:25 +02:00
|
|
|
- name: Should be idempotent with a dual NICs
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name2 }}"
|
2018-04-26 08:16:25 +02:00
|
|
|
vm_size: Standard_A0
|
|
|
|
storage_account: "{{ storage_account }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
storage_container: "{{ vm_name2 }}"
|
|
|
|
storage_blob: "{{ vm_name2 }}.vhd"
|
2018-04-26 08:16:25 +02:00
|
|
|
admin_username: adminuser
|
|
|
|
admin_password: Password123!
|
|
|
|
short_hostname: testvm
|
|
|
|
os_type: Linux
|
2018-08-23 09:36:58 +02:00
|
|
|
os_disk_size_gb: 64
|
2018-04-26 08:16:25 +02:00
|
|
|
network_interfaces: "{{ niclist }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
availability_set: "{{ abs_name2 }}"
|
2018-04-26 08:16:25 +02:00
|
|
|
image:
|
|
|
|
offer: UbuntuServer
|
|
|
|
publisher: Canonical
|
|
|
|
sku: 16.04-LTS
|
|
|
|
version: latest
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
2018-12-10 09:21:09 +01:00
|
|
|
- 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'
|
|
|
|
|
2018-04-26 08:16:25 +02:00
|
|
|
- name: Delete dual NIC VM
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-08-31 06:14:55 +02:00
|
|
|
name: "{{ vm_name2 }}"
|
2018-04-26 08:16:25 +02:00
|
|
|
state: absent
|
|
|
|
vm_size: Standard_A0
|
2018-08-31 06:14:55 +02:00
|
|
|
async: 5000
|
|
|
|
poll: 0
|
2018-04-26 08:16:25 +02:00
|
|
|
|
2017-11-10 00:48:14 +01:00
|
|
|
# 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
|
2018-01-17 06:05:35 +01:00
|
|
|
failed_when: fail_missing_custom_image_dict.msg != "Error could not find image with name invalid-image"
|
2018-08-30 02:14:44 +02:00
|
|
|
|
|
|
|
## 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
|
2019-01-28 05:27:32 +01:00
|
|
|
|
|
|
|
- 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:
|
2019-05-14 21:06:07 +02:00
|
|
|
# what about the default storage group?
|
2019-01-28 05:27:32 +01:00
|
|
|
- output_nic.ansible_facts.azure_networkinterfaces | length == 0
|
|
|
|
- output_nsg.ansible_facts.azure_securitygroups | length == 0
|
|
|
|
- output_pip.ansible_facts.azure_publicipaddresses | length == 0
|