2018-05-17 05:28:30 +02:00
|
|
|
- name: Prepare random number
|
|
|
|
set_fact:
|
|
|
|
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
run_once: yes
|
|
|
|
|
2017-08-29 23:14:15 +02:00
|
|
|
- name: Create virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testVnet
|
|
|
|
address_prefixes: "10.0.0.0/16"
|
|
|
|
|
|
|
|
- name: Add subnet
|
|
|
|
azure_rm_subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testSubnet
|
|
|
|
address_prefix: "10.0.1.0/24"
|
|
|
|
virtual_network: testVnet
|
|
|
|
|
|
|
|
- name: Create public IP address
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2017-12-21 06:13:09 +01:00
|
|
|
allocation_method: Static
|
2017-08-29 23:14:15 +02:00
|
|
|
name: testPublicIP
|
|
|
|
|
2017-12-21 06:13:09 +01:00
|
|
|
- name: Create load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testLB
|
|
|
|
public_ip_address_name: testPublicIP
|
|
|
|
|
2017-08-29 23:14:15 +02:00
|
|
|
- name: Create VMSS
|
|
|
|
azure_rm_virtualmachine_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-17 05:28:30 +02:00
|
|
|
name: testVMSS{{ rpfx }}
|
2017-08-29 23:14:15 +02:00
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
admin_username: testuser
|
|
|
|
ssh_password_enabled: true
|
|
|
|
admin_password: "Password1234!"
|
|
|
|
capacity: 2
|
|
|
|
virtual_network_name: testVnet
|
|
|
|
subnet_name: testSubnet
|
|
|
|
upgrade_policy: Manual
|
|
|
|
tier: Standard
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
os_disk_caching: ReadWrite
|
|
|
|
image:
|
|
|
|
offer: CoreOS
|
|
|
|
publisher: CoreOS
|
|
|
|
sku: Stable
|
|
|
|
version: latest
|
|
|
|
data_disks:
|
|
|
|
- lun: 0
|
|
|
|
disk_size_gb: 64
|
|
|
|
caching: ReadWrite
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
register: results
|
|
|
|
|
2018-08-14 07:24:34 +02:00
|
|
|
- name: Assert that VMSS was created
|
|
|
|
assert:
|
|
|
|
that: results.changed
|
|
|
|
|
|
|
|
- name: Create VMSS -- test upgrade_policy idempotence
|
|
|
|
azure_rm_virtualmachine_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testVMSS{{ rpfx }}
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
admin_username: testuser
|
|
|
|
ssh_password_enabled: true
|
|
|
|
admin_password: "Password1234!"
|
|
|
|
capacity: 2
|
|
|
|
virtual_network_name: testVnet
|
|
|
|
subnet_name: testSubnet
|
|
|
|
upgrade_policy: Automatic
|
|
|
|
tier: Standard
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
os_disk_caching: ReadWrite
|
|
|
|
image:
|
|
|
|
offer: CoreOS
|
|
|
|
publisher: CoreOS
|
|
|
|
sku: Stable
|
|
|
|
version: latest
|
|
|
|
data_disks:
|
|
|
|
- lun: 0
|
|
|
|
disk_size_gb: 64
|
|
|
|
caching: ReadWrite
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
check_mode: yes
|
|
|
|
register: results
|
|
|
|
|
2018-05-17 05:28:30 +02:00
|
|
|
- name: Assert that VMSS was created
|
2017-08-29 23:14:15 +02:00
|
|
|
assert:
|
|
|
|
that: results.changed
|
|
|
|
|
2018-05-17 05:28:30 +02:00
|
|
|
- name: Retrieve scaleset facts
|
|
|
|
azure_rm_virtualmachine_scaleset_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testVMSS{{ rpfx }}
|
|
|
|
format: curated
|
|
|
|
register: output_scaleset
|
|
|
|
|
|
|
|
- name: Get scaleset body
|
|
|
|
set_fact:
|
2018-08-16 08:45:36 +02:00
|
|
|
body: "{{ output_scaleset.vmss[0] }}"
|
2018-05-17 05:28:30 +02:00
|
|
|
|
|
|
|
- name: Try to update VMSS using output as input
|
|
|
|
azure_rm_virtualmachine_scaleset:
|
|
|
|
resource_group: "{{ body.resource_group }}"
|
|
|
|
name: "{{ body.name }}"
|
|
|
|
vm_size: "{{ body.vm_size }}"
|
|
|
|
admin_username: "{{ body.admin_username }}"
|
|
|
|
ssh_password_enabled: "{{ body.ssh_password_enabled }}"
|
|
|
|
admin_password: "Password1234!"
|
|
|
|
capacity: "{{ body.capacity }}"
|
|
|
|
virtual_network_name: "{{ body.virtual_network_name }}"
|
|
|
|
subnet_name: "{{ body.subnet_name }}"
|
|
|
|
upgrade_policy: "{{ body.upgrade_policy }}"
|
|
|
|
tier: "{{ body.tier }}"
|
|
|
|
managed_disk_type: "{{ body.managed_disk_type }}"
|
|
|
|
os_disk_caching: "{{ body.os_disk_caching }}"
|
|
|
|
image: "{{ body.image }}"
|
|
|
|
data_disks: "{{ body.data_disks }}"
|
|
|
|
register: results
|
|
|
|
|
|
|
|
- name: Assert that VMSS was updated
|
|
|
|
assert:
|
|
|
|
that: not results.changed
|
|
|
|
|
2017-08-29 23:14:15 +02:00
|
|
|
- name: Delete VMSS
|
|
|
|
azure_rm_virtualmachine_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-17 05:28:30 +02:00
|
|
|
name: testVMSS{{ rpfx }}
|
2017-08-29 23:14:15 +02:00
|
|
|
state: absent
|
|
|
|
remove_on_absent: ['all']
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
admin_username: testuser
|
|
|
|
capacity: 2
|
|
|
|
virtual_network_name: testVnet
|
|
|
|
subnet_name: testSubnet
|
|
|
|
upgrade_policy: Manual
|
|
|
|
tier: Standard
|
|
|
|
os_disk_caching: ReadWrite
|
|
|
|
image:
|
|
|
|
offer: CoreOS
|
|
|
|
publisher: CoreOS
|
|
|
|
sku: Stable
|
|
|
|
version: latest
|
|
|
|
data_disks:
|
|
|
|
- lun: 0
|
|
|
|
disk_size_gb: 64
|
|
|
|
caching: ReadWrite
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
|
2017-12-21 06:13:09 +01:00
|
|
|
- name: Create VMSS (check mode)
|
|
|
|
azure_rm_virtualmachine_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-17 05:28:30 +02:00
|
|
|
name: testVMSS{{ rpfx }}1
|
2017-12-21 06:13:09 +01:00
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
admin_username: testuser
|
|
|
|
ssh_password_enabled: true
|
|
|
|
admin_password: "Password1234!"
|
|
|
|
capacity: 2
|
|
|
|
virtual_network_name: testVnet
|
|
|
|
subnet_name: testSubnet
|
|
|
|
load_balancer: testLB
|
|
|
|
upgrade_policy: Manual
|
|
|
|
tier: Standard
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
os_disk_caching: ReadWrite
|
|
|
|
image:
|
|
|
|
offer: CoreOS
|
|
|
|
publisher: CoreOS
|
|
|
|
sku: Stable
|
|
|
|
version: latest
|
|
|
|
data_disks:
|
|
|
|
- lun: 0
|
|
|
|
disk_size_gb: 64
|
|
|
|
caching: ReadWrite
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
register: results
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: Assert that VMSS can be created
|
|
|
|
assert:
|
|
|
|
that: results.changed
|
|
|
|
|
|
|
|
- name: Create VMSS (check mode)
|
|
|
|
azure_rm_virtualmachine_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-17 05:28:30 +02:00
|
|
|
name: testVMSS{{ rpfx }}1
|
2017-12-21 06:13:09 +01:00
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
admin_username: testuser
|
|
|
|
ssh_password_enabled: true
|
|
|
|
admin_password: "Password1234!"
|
|
|
|
capacity: 2
|
|
|
|
virtual_network_name: testVnet
|
|
|
|
subnet_name: testSubnet
|
|
|
|
load_balancer: testLB
|
|
|
|
upgrade_policy: Manual
|
|
|
|
tier: Standard
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
os_disk_caching: ReadWrite
|
|
|
|
image:
|
|
|
|
offer: CoreOS
|
|
|
|
publisher: CoreOS
|
|
|
|
sku: Stable
|
|
|
|
version: latest
|
|
|
|
data_disks:
|
|
|
|
- lun: 0
|
|
|
|
disk_size_gb: 64
|
|
|
|
caching: ReadWrite
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
register: results
|
|
|
|
|
|
|
|
- name: Assert that VMSS ran
|
|
|
|
assert:
|
|
|
|
that: results.changed
|
|
|
|
|
|
|
|
- name: Delete VMSS
|
|
|
|
azure_rm_virtualmachine_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-17 05:28:30 +02:00
|
|
|
name: testVMSS{{ rpfx }}1
|
2017-12-21 06:13:09 +01:00
|
|
|
state: absent
|
|
|
|
remove_on_absent: ['all']
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
admin_username: testuser
|
|
|
|
capacity: 2
|
|
|
|
virtual_network_name: testVnet
|
|
|
|
subnet_name: testSubnet
|
|
|
|
upgrade_policy: Manual
|
|
|
|
tier: Standard
|
|
|
|
os_disk_caching: ReadWrite
|
|
|
|
image:
|
|
|
|
offer: CoreOS
|
|
|
|
publisher: CoreOS
|
|
|
|
sku: Stable
|
|
|
|
version: latest
|
|
|
|
data_disks:
|
|
|
|
- lun: 0
|
|
|
|
disk_size_gb: 64
|
|
|
|
caching: ReadWrite
|
|
|
|
managed_disk_type: Standard_LRS
|
|
|
|
|
|
|
|
- name: Delete load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testLB
|
|
|
|
state: absent
|
|
|
|
|
2017-08-29 23:14:15 +02:00
|
|
|
- name: Delete public IP address
|
|
|
|
azure_rm_publicipaddress:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
state: absent
|
|
|
|
name: testPublicIP
|
|
|
|
|
|
|
|
- name: Delete virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testVnet
|
|
|
|
state: absent
|
|
|
|
address_prefixes: "10.0.0.0/16"
|
2017-12-20 22:17:57 +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_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testvm002
|
|
|
|
state: present
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
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_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testvm002
|
|
|
|
state: present
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
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_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testvm002
|
|
|
|
state: present
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
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_scaleset:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: testvm002
|
|
|
|
state: present
|
|
|
|
vm_size: Standard_DS1_v2
|
|
|
|
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"
|