2018-05-29 08:22:59 +02:00
|
|
|
- name: Prepare random number
|
|
|
|
set_fact:
|
|
|
|
vnetname: "vnet{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
|
2017-08-12 10:03:42 +02:00
|
|
|
- name: Delete virtual network, if it exists
|
|
|
|
azure_rm_virtualnetwork:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
state: absent
|
|
|
|
|
2018-05-28 09:45:01 +02:00
|
|
|
- name: Create virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2018-05-28 09:45:01 +02:00
|
|
|
address_prefixes_cidr:
|
|
|
|
- 10.1.0.0/16
|
|
|
|
- 172.100.0.0/16
|
|
|
|
tags:
|
|
|
|
testing: testing
|
|
|
|
delete: on-exit
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
|
2017-08-12 10:03:42 +02:00
|
|
|
- name: Create virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
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"
|
|
|
|
|
2019-01-10 08:53:23 +01:00
|
|
|
- name: Attach a subnet
|
|
|
|
azure_rm_subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
name: "{{ vnetname }}"
|
|
|
|
virtual_network_name: "{{ vnetname }}"
|
|
|
|
address_prefix_cidr: "10.1.0.0/24"
|
|
|
|
|
2017-08-12 10:03:42 +02:00
|
|
|
- name: Gather facts by name, tags
|
|
|
|
azure_rm_virtualnetwork_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
tags:
|
|
|
|
- testing
|
2019-01-10 08:53:23 +01:00
|
|
|
register: facts
|
2017-08-12 10:03:42 +02:00
|
|
|
|
|
|
|
- assert:
|
2019-01-10 08:53:23 +01:00
|
|
|
that:
|
|
|
|
- "azure_virtualnetworks | length == 1"
|
|
|
|
- "facts.virtualnetworks | length == 1"
|
|
|
|
- "facts.virtualnetworks[0].dns_servers | length == 2"
|
|
|
|
- "facts.virtualnetworks[0].address_prefixes | length == 2"
|
|
|
|
- "facts.virtualnetworks[0].subnets | length == 1"
|
2017-08-12 10:03:42 +02:00
|
|
|
|
|
|
|
- name: Gather facts by resource group, tags
|
|
|
|
azure_rm_virtualnetwork_facts:
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
tags:
|
|
|
|
- testing
|
|
|
|
|
|
|
|
- assert:
|
2019-06-07 19:22:26 +02:00
|
|
|
that: "azure_virtualnetworks | length >= 1"
|
2017-08-12 10:03:42 +02:00
|
|
|
|
|
|
|
- name: Gather facts by tags
|
|
|
|
azure_rm_virtualnetwork_facts:
|
|
|
|
tags:
|
|
|
|
- testing
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: "azure_virtualnetworks | length >= 1"
|
|
|
|
|
|
|
|
- name: Should be idempotent
|
|
|
|
azure_rm_virtualnetwork:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
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:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
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:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2018-08-16 05:35:39 +02:00
|
|
|
append_tags: no
|
2017-08-12 10:03:42 +02:00
|
|
|
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:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
purge_address_prefixes: true
|
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
register: output
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that: output.failed
|
|
|
|
|
|
|
|
- name: Purge address prefixes
|
|
|
|
azure_rm_virtualnetwork:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
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:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
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 }}"
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2019-01-10 08:53:23 +01:00
|
|
|
register: facts
|
2017-08-12 10:03:42 +02:00
|
|
|
|
|
|
|
- assert:
|
2019-01-10 08:53:23 +01:00
|
|
|
that:
|
|
|
|
- azure_virtualnetworks | length == 1
|
|
|
|
- facts.virtualnetworks | length == 1
|
|
|
|
- "facts.virtualnetworks[0].subnets | length == 1"
|
2017-08-12 10:03:42 +02:00
|
|
|
|
|
|
|
- name: Delete virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
2018-05-29 08:22:59 +02:00
|
|
|
name: "{{ vnetname }}"
|
2017-08-12 10:03:42 +02:00
|
|
|
resource_group: "{{ resource_group }}"
|
|
|
|
state: absent
|