2017-08-12 10:03:42 +02:00
|
|
|
- name: Get resource group
|
2019-06-06 06:10:27 +02:00
|
|
|
azure_rm_resourcegroup_info:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_group }}"
|
|
|
|
|
2017-08-12 01:16:39 +02:00
|
|
|
- name: Create resource group
|
|
|
|
azure_rm_resourcegroup:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_prefix }}"
|
|
|
|
location: "{{ azure_resourcegroups[0].location }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.tags.testing == 'testing'
|
|
|
|
- output.state.tags.delete == 'never'
|
|
|
|
- output.state.location == '{{ location }}'
|
|
|
|
|
|
|
|
- name: Should be idempotent
|
|
|
|
azure_rm_resourcegroup:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_prefix }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: never
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
|
|
|
- name: Change resource group tags
|
|
|
|
azure_rm_resourcegroup:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_prefix }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
tags:
|
|
|
|
testing: 'no'
|
|
|
|
delete: 'on-exit'
|
|
|
|
foo: 'bar'
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.tags | length == 3
|
|
|
|
- output.state.tags.testing == 'no'
|
|
|
|
- output.state.tags.delete == 'on-exit'
|
|
|
|
- output.state.tags.foo == 'bar'
|
|
|
|
|
|
|
|
- name: Gather facts by tags
|
2019-06-06 06:10:27 +02:00
|
|
|
azure_rm_resourcegroup_info:
|
2017-08-12 01:16:39 +02:00
|
|
|
tags:
|
|
|
|
- testing
|
|
|
|
- foo:bar
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_resourcegroups | length == 1
|
|
|
|
|
|
|
|
- name: Purge one tag
|
|
|
|
azure_rm_resourcegroup:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_prefix }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
tags:
|
|
|
|
testing: 'no'
|
|
|
|
delete: 'on-exit'
|
|
|
|
debug: yes
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.tags | length == 2
|
|
|
|
- output.state.tags.testing == 'no'
|
|
|
|
- output.state.tags.delete == 'on-exit'
|
|
|
|
|
|
|
|
- name: Purge no tags
|
|
|
|
azure_rm_resourcegroup:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_prefix }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.tags | length == 2
|
|
|
|
|
|
|
|
- name: Purge all tags
|
|
|
|
azure_rm_resourcegroup:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_prefix }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
tags: {}
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.state.tags | length == 0
|
|
|
|
|
|
|
|
- name: Add a resource
|
|
|
|
azure_rm_virtualnetwork:
|
2017-08-12 10:03:42 +02:00
|
|
|
resource_group: "{{ resource_prefix }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
name: "virtualnet01"
|
|
|
|
address_prefixes_cidr: '10.1.0.0/16'
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Remove resource group should fail
|
|
|
|
azure_rm_resourcegroup:
|
2017-08-12 10:03:42 +02:00
|
|
|
name: "{{ resource_prefix }}"
|
2017-08-12 01:16:39 +02:00
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- output.failed
|
|
|
|
- "'Resources exist' in output.msg"
|
|
|
|
|
|
|
|
- name: Create a second resource group
|
|
|
|
azure_rm_resourcegroup:
|
|
|
|
name: Testing2
|
|
|
|
location: "{{ location }}"
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Gather facts for a resource group
|
2019-06-06 06:10:27 +02:00
|
|
|
azure_rm_resourcegroup_info:
|
2017-08-12 01:16:39 +02:00
|
|
|
name: "{{ resource_group }}"
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_resourcegroups | length == 1
|
|
|
|
|
|
|
|
- name: Gather facts for all resource groups
|
2019-06-06 06:10:27 +02:00
|
|
|
azure_rm_resourcegroup_info:
|
2017-08-12 01:16:39 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: azure_resourcegroups | length > 1
|
|
|
|
|
|
|
|
- name: Force remove resource group
|
|
|
|
azure_rm_resourcegroup:
|
|
|
|
name: "{{ resource_group }}"
|
|
|
|
state: absent
|
|
|
|
force: yes
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Remove second resource group
|
|
|
|
azure_rm_resourcegroup:
|
|
|
|
name: Testing2
|
|
|
|
state: absent
|
|
|
|
register: output
|