mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
164 lines
3.8 KiB
YAML
164 lines
3.8 KiB
YAML
- name: Prepare random number
|
|
set_fact:
|
|
vnetname: "vnet{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
- name: Delete virtual network, if it exists
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
resource_group: "{{ resource_group }}"
|
|
state: absent
|
|
|
|
- name: Create virtual network
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
address_prefixes_cidr:
|
|
- 10.1.0.0/16
|
|
- 172.100.0.0/16
|
|
tags:
|
|
testing: testing
|
|
delete: on-exit
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
- name: Create virtual network
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
address_prefixes_cidr:
|
|
- 10.1.0.0/16
|
|
- 172.100.0.0/16
|
|
dns_servers:
|
|
- 127.0.0.1
|
|
- 127.0.0.3
|
|
tags:
|
|
testing: testing
|
|
delete: on-exit
|
|
resource_group: "{{ resource_group }}"
|
|
register: output
|
|
|
|
- assert:
|
|
that:
|
|
- "output.state.address_prefixes | length == 2"
|
|
- "output.state.dns_servers | length == 2"
|
|
- "output.state.tags.delete == 'on-exit'"
|
|
- "output.state.tags | length == 2"
|
|
|
|
- name: Gather facts by name, tags
|
|
azure_rm_virtualnetwork_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ vnetname }}"
|
|
tags:
|
|
- testing
|
|
|
|
- assert:
|
|
that: "azure_virtualnetworks | length == 1"
|
|
|
|
- name: Gather facts by resource group, tags
|
|
azure_rm_virtualnetwork_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
tags:
|
|
- testing
|
|
|
|
- assert:
|
|
that: "azure_virtualnetworks | length == 1"
|
|
|
|
- name: Gather facts by tags
|
|
azure_rm_virtualnetwork_facts:
|
|
tags:
|
|
- testing
|
|
|
|
- assert:
|
|
that: "azure_virtualnetworks | length >= 1"
|
|
|
|
- name: Should be idempotent
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
address_prefixes_cidr:
|
|
- 10.1.0.0/16
|
|
- 172.100.0.0/16
|
|
dns_servers:
|
|
- 127.0.0.1
|
|
- 127.0.0.3
|
|
tags:
|
|
testing: testing
|
|
delete: on-exit
|
|
resource_group: "{{ resource_group }}"
|
|
register: output
|
|
|
|
- assert:
|
|
that: not output.changed
|
|
|
|
- name: Update tags
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
tags:
|
|
testing: 'no'
|
|
delete: never
|
|
foo: bar
|
|
resource_group: "{{ resource_group }}"
|
|
register: output
|
|
|
|
- assert:
|
|
that: output.state.tags | length == 3
|
|
|
|
- name: Purge tags
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
append_tags: no
|
|
tags:
|
|
testing: 'always'
|
|
resource_group: "{{ resource_group }}"
|
|
register: output
|
|
|
|
- assert:
|
|
that:
|
|
- output.state.tags | length == 1
|
|
- output.state.tags.testing == 'always'
|
|
|
|
- name: Should require address_prefixes_cidr when purge_address_prefixes
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
purge_address_prefixes: true
|
|
resource_group: "{{ resource_group }}"
|
|
register: output
|
|
ignore_errors: yes
|
|
|
|
- assert:
|
|
that: output.failed
|
|
|
|
- name: Purge address prefixes
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
address_prefixes_cidr: 10.1.0.0/16
|
|
purge_address_prefixes: true
|
|
resource_group: "{{ resource_group }}"
|
|
register: output
|
|
|
|
- assert:
|
|
that:
|
|
- output.state.address_prefixes | length == 1
|
|
- output.state.address_prefixes[0] == '10.1.0.0/16'
|
|
- output.state.dns_servers | length == 2
|
|
- output.state.dns_servers[0] == '127.0.0.1'
|
|
|
|
- name: Purge DNS servers
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
purge_dns_servers: true
|
|
resource_group: "{{ resource_group }}"
|
|
register: output
|
|
|
|
- assert:
|
|
that: output.state['dns_servers'] is undefined
|
|
|
|
- name: Gather facts
|
|
azure_rm_virtualnetwork_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ vnetname }}"
|
|
|
|
- assert:
|
|
that: "azure_virtualnetworks | length == 1"
|
|
|
|
- name: Delete virtual network
|
|
azure_rm_virtualnetwork:
|
|
name: "{{ vnetname }}"
|
|
resource_group: "{{ resource_group }}"
|
|
state: absent
|