mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ccb7909cc5
* add traffic manager client and models in azure_rm_common - add traffic manager management client - import traffic manager models to 'traffic_manager_models' proprety - azure.mgmt.trafficmanager doesn't have models(), so use direct import for now * add traffic manager facts module * add traffic manager module * add integration test for two modules * fix package info in requirements * fix sanity check * fix monitor config default value * fix facts module doc * move model import into module * resolve comments except seprating endpoint * remove endpoint operation * fix test after removing endpoint operation * change module name to azure_rm_trafficmanagerprofile/facts * fix sanity test * seperate endpoint into delegate module * fix typo * fix lint * fix lint * fix test * fix test * resolve comments * fix test * fix test * fix test * fix bug in return * resolve comments * fix lint * fix lint * add sample in endpoint module
289 lines
7.1 KiB
YAML
289 lines
7.1 KiB
YAML
- name: Prepare random number
|
|
set_fact:
|
|
tmname: "tm{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
endpointname1: "ep1{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
endpointname2: "ep2{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
run_once: yes
|
|
|
|
|
|
- name: Create a Traffic Manager profile(check mode)
|
|
azure_rm_trafficmanagerprofile:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
tags:
|
|
testing: testing
|
|
delete: on-exit
|
|
foo: bar
|
|
location: global
|
|
profile_status: enabled
|
|
routing_method: performance
|
|
dns_config:
|
|
relative_name: "{{ tmname }}"
|
|
ttl: 60
|
|
monitor_config:
|
|
protocol: HTTPS
|
|
port: 80
|
|
path: '/'
|
|
check_mode: yes
|
|
|
|
- name: Check there is no Traffic Manager profile created
|
|
azure_rm_trafficmanagerprofile_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
register: fact
|
|
|
|
- name: Check there is no Traffic Manager profile created
|
|
assert: { that: "{{ fact.tms | length }} == 0" }
|
|
|
|
- name: Create a Traffic Manager profile
|
|
azure_rm_trafficmanagerprofile:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
tags:
|
|
testing: testing
|
|
delete: on-exit
|
|
foo: bar
|
|
location: global
|
|
profile_status: enabled
|
|
routing_method: performance
|
|
dns_config:
|
|
relative_name: "{{ tmname }}"
|
|
ttl: 60
|
|
monitor_config:
|
|
protocol: HTTPS
|
|
port: 80
|
|
path: '/'
|
|
register: tm
|
|
|
|
- name: Assert the Traffic Manager profile is well created
|
|
assert:
|
|
that:
|
|
- tm.changed
|
|
|
|
- name: Gather Traffic Manager profile facts
|
|
azure_rm_trafficmanagerprofile_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
register: fact
|
|
|
|
- name: Assert fact returns the created one
|
|
assert:
|
|
that:
|
|
- "fact.tms | length == 1"
|
|
- fact.tms[0].id == tm.id
|
|
- fact.tms[0].endpoints | length == 0
|
|
|
|
- name: Create a Traffic Manager profile (idempotent)
|
|
azure_rm_trafficmanagerprofile:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
tags:
|
|
testing: testing
|
|
delete: on-exit
|
|
foo: bar
|
|
location: global
|
|
profile_status: enabled
|
|
routing_method: performance
|
|
dns_config:
|
|
relative_name: "{{ tmname }}"
|
|
ttl: 60
|
|
monitor_config:
|
|
protocol: HTTPS
|
|
port: 80
|
|
path: '/'
|
|
register: output
|
|
|
|
- name: Assert idempotent
|
|
assert:
|
|
that:
|
|
- not output.changed
|
|
|
|
- name: Update the Traffic Manager profile
|
|
azure_rm_trafficmanagerprofile:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
tags:
|
|
testing: testing
|
|
delete: on-exit
|
|
foo: bar
|
|
location: global
|
|
profile_status: disabled
|
|
routing_method: priority
|
|
dns_config:
|
|
relative_name: "{{ tmname }}"
|
|
ttl: 60
|
|
monitor_config:
|
|
protocol: HTTPS
|
|
port: 80
|
|
path: '/'
|
|
register: output
|
|
|
|
- name: Assert the Traffic Manager profile is updated
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
|
|
- name: Create Traffic Manager endpoint(check mode)
|
|
azure_rm_trafficmanagerendpoint:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
name: "{{ endpointname1 }}"
|
|
type: external_endpoints
|
|
location: westus
|
|
priority: 2
|
|
weight: 1
|
|
target: 1.2.3.4
|
|
check_mode: yes
|
|
register: output
|
|
|
|
- name: Assert check mode changed
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
|
|
- name: Get endpoint
|
|
azure_rm_trafficmanagerendpoint_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
register: facts
|
|
|
|
- name: Check no endpoint created in check mode
|
|
assert:
|
|
that:
|
|
- facts.endpoints | length == 0
|
|
|
|
- name: Create Traffic Manager endpoint
|
|
azure_rm_trafficmanagerendpoint:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
name: "{{ endpointname1 }}"
|
|
type: external_endpoints
|
|
location: westus
|
|
priority: 2
|
|
weight: 1
|
|
target: 1.2.3.4
|
|
register: output
|
|
|
|
- name: Assert endpoint create changed
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
|
|
- name: Get endpoint
|
|
azure_rm_trafficmanagerendpoint_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
register: facts
|
|
|
|
- name: Check endpoint created
|
|
assert:
|
|
that:
|
|
- facts.endpoints | length == 1
|
|
- facts.endpoints[0].name == "{{ endpointname1 }}"
|
|
|
|
- name: Create second Traffic Manager endpoint
|
|
azure_rm_trafficmanagerendpoint:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
name: "{{ endpointname2 }}"
|
|
type: external_endpoints
|
|
location: westus
|
|
priority: 1
|
|
weight: 3
|
|
target: 4.3.2.1
|
|
|
|
- name: Get endpoint
|
|
azure_rm_trafficmanagerendpoint_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
register: facts
|
|
|
|
- name: Check 2 endpoint in profile
|
|
assert:
|
|
that:
|
|
- facts.endpoints | length == 2
|
|
|
|
- name: Create endpoint (idempotent)
|
|
azure_rm_trafficmanagerendpoint:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
name: "{{ endpointname2 }}"
|
|
type: external_endpoints
|
|
location: westus
|
|
priority: 1
|
|
weight: 3
|
|
target: 4.3.2.1
|
|
register: output
|
|
|
|
- name: Assert endpoint creation idempotent
|
|
assert:
|
|
that:
|
|
- output.changed == False
|
|
|
|
- name: Delete second endpoint
|
|
azure_rm_trafficmanagerendpoint:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
name: "{{ endpointname2 }}"
|
|
type: external_endpoints
|
|
state: absent
|
|
register: output
|
|
|
|
- name: Assert endpoint deletion changed
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
|
|
- name: Get endpoint
|
|
azure_rm_trafficmanagerendpoint_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
profile_name: "{{ tmname }}"
|
|
register: facts
|
|
|
|
- name: Check 1 endpoint left in profile
|
|
assert:
|
|
that:
|
|
- facts.endpoints | length == 1
|
|
|
|
- name: Delete the Traffic Manager profile(check mode)
|
|
azure_rm_trafficmanagerprofile:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
state: absent
|
|
check_mode: yes
|
|
|
|
- name: Gather Traffic Manager profile facts
|
|
azure_rm_trafficmanagerprofile_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
register: fact
|
|
|
|
- name: Assert the traffic manager profile is still there
|
|
assert:
|
|
that:
|
|
- "fact.tms | length == 1"
|
|
- fact.tms[0].id == tm.id
|
|
- fact.tms[0].endpoints | length == 1
|
|
|
|
- name: Delete the Traffic Manager profile
|
|
azure_rm_trafficmanagerprofile:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
state: absent
|
|
register: output
|
|
|
|
- name: Assert the Traffic Manager profile is well deleted
|
|
assert:
|
|
that:
|
|
- output.changed
|
|
|
|
- name: Get Traffic Manager profile fact
|
|
azure_rm_trafficmanagerprofile_facts:
|
|
resource_group: "{{ resource_group }}"
|
|
name: "{{ tmname }}"
|
|
register: fact
|
|
|
|
- name: Assert fact returns empty
|
|
assert:
|
|
that:
|
|
- "fact.tms | length == 0"
|