2018-05-29 06:22:59 +00:00
|
|
|
- name: Prepare random number
|
|
|
|
set_fact:
|
|
|
|
pipaname: "pipa{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
pipbname: "pipb{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
lbvnname: "lbvn{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
2018-06-12 02:52:07 +00:00
|
|
|
lbname_a: "lba{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
lbname_b: "lbb{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
lbname_c: "lbc{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
|
|
|
lbname_d: "lbd{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
|
2018-05-29 06:22:59 +00:00
|
|
|
run_once: yes
|
|
|
|
|
2018-05-04 05:17:05 +00:00
|
|
|
- name: create public ip
|
|
|
|
azure_rm_publicipaddress:
|
2018-05-29 06:22:59 +00:00
|
|
|
name: "{{ pipbname }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
sku: Standard
|
|
|
|
allocation_method: Static
|
|
|
|
resource_group: '{{ resource_group }}'
|
|
|
|
|
2017-08-29 21:29:44 +00:00
|
|
|
- name: create public ip
|
|
|
|
azure_rm_publicipaddress:
|
2018-05-29 06:22:59 +00:00
|
|
|
name: "{{ pipaname }}"
|
2017-08-29 21:29:44 +00:00
|
|
|
resource_group: '{{ resource_group }}'
|
|
|
|
|
2018-02-08 09:32:27 +00:00
|
|
|
- name: clear load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_a }}"
|
2018-02-08 09:32:27 +00:00
|
|
|
state: absent
|
|
|
|
|
2017-08-29 21:29:44 +00:00
|
|
|
- name: create load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_a }}"
|
2018-05-29 06:22:59 +00:00
|
|
|
public_ip: "{{ pipaname }}"
|
2017-08-29 21:29:44 +00:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: assert load balancer created
|
|
|
|
assert:
|
|
|
|
that: output.changed
|
|
|
|
|
|
|
|
- name: delete load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_a }}"
|
2017-08-29 21:29:44 +00:00
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: assert load balancer deleted
|
|
|
|
assert:
|
|
|
|
that: output.changed
|
|
|
|
|
2018-02-08 09:32:27 +00:00
|
|
|
- name: delete load balancer (idempotent)
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_a }}"
|
2018-02-08 09:32:27 +00:00
|
|
|
state: absent
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: assert load balancer deleted (idempotent)
|
|
|
|
assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
2017-08-29 21:29:44 +00:00
|
|
|
- name: create another load balancer with more options
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_b }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
sku: Standard
|
2018-05-29 06:22:59 +00:00
|
|
|
public_ip_address: "{{ pipbname }}"
|
2017-08-29 21:29:44 +00:00
|
|
|
probe_protocol: Tcp
|
|
|
|
probe_port: 80
|
|
|
|
probe_interval: 10
|
|
|
|
probe_fail_count: 3
|
|
|
|
protocol: Tcp
|
|
|
|
load_distribution: Default
|
|
|
|
frontend_port: 80
|
|
|
|
backend_port: 8080
|
|
|
|
idle_timeout: 4
|
|
|
|
natpool_frontend_port_start: 30
|
|
|
|
natpool_frontend_port_end: 40
|
|
|
|
natpool_backend_port: 80
|
|
|
|
natpool_protocol: Tcp
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: assert complex load balancer created
|
|
|
|
assert:
|
2018-05-04 05:17:05 +00:00
|
|
|
that:
|
|
|
|
- output.changed
|
|
|
|
- output.state.sku == 'Standard'
|
2017-08-29 21:29:44 +00:00
|
|
|
|
|
|
|
- name: delete load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_b }}"
|
2017-08-29 21:29:44 +00:00
|
|
|
state: absent
|
|
|
|
|
2018-02-08 09:32:27 +00:00
|
|
|
- name: create load balancer with multiple parameters
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_c }}"
|
2018-02-08 09:32:27 +00:00
|
|
|
frontend_ip_configurations:
|
|
|
|
- name: frontendipconf0
|
2018-05-29 06:22:59 +00:00
|
|
|
public_ip_address: "{{ pipaname }}"
|
2018-02-08 09:32:27 +00:00
|
|
|
backend_address_pools:
|
|
|
|
- name: backendaddrpool0
|
|
|
|
probes:
|
|
|
|
- name: prob0
|
|
|
|
port: 80
|
|
|
|
inbound_nat_pools:
|
|
|
|
- name: inboundnatpool0
|
|
|
|
frontend_ip_configuration_name: frontendipconf0
|
|
|
|
protocol: Tcp
|
|
|
|
frontend_port_range_start: 80
|
|
|
|
frontend_port_range_end: 81
|
|
|
|
backend_port: 8080
|
|
|
|
load_balancing_rules:
|
|
|
|
- name: lbrbalancingrule0
|
|
|
|
frontend_ip_configuration: frontendipconf0
|
|
|
|
backend_address_pool: backendaddrpool0
|
|
|
|
frontend_port: 80
|
|
|
|
backend_port: 80
|
|
|
|
probe: prob0
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: assert complex load balancer created
|
|
|
|
assert:
|
|
|
|
that: output.changed
|
|
|
|
|
|
|
|
- name: delete load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_c }}"
|
2018-02-08 09:32:27 +00:00
|
|
|
state: absent
|
|
|
|
|
2018-05-04 05:17:05 +00:00
|
|
|
- name: Create virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-29 06:22:59 +00:00
|
|
|
name: "{{ lbvnname }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
address_prefixes: "10.10.0.0/16"
|
|
|
|
|
|
|
|
- name: Add subnet
|
|
|
|
azure_rm_subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-29 06:22:59 +00:00
|
|
|
name: "lb{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}sb"
|
2018-05-04 05:17:05 +00:00
|
|
|
address_prefix: "10.10.0.0/24"
|
2018-05-29 06:22:59 +00:00
|
|
|
virtual_network: "{{ lbvnname }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
register: subnet
|
|
|
|
|
|
|
|
- name: create internal loadbalancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_d }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
frontend_ip_configurations:
|
|
|
|
- name: frontendipconf0
|
|
|
|
private_ip_address: 10.10.0.10
|
|
|
|
private_ip_allocation_method: Static
|
|
|
|
subnet: "{{ subnet.state.id }}"
|
|
|
|
backend_address_pools:
|
|
|
|
- name: backendaddrpool0
|
|
|
|
probes:
|
|
|
|
- name: prob0
|
|
|
|
port: 80
|
|
|
|
inbound_nat_pools:
|
|
|
|
- name: inboundnatpool0
|
|
|
|
frontend_ip_configuration_name: frontendipconf0
|
|
|
|
protocol: Tcp
|
|
|
|
frontend_port_range_start: 80
|
|
|
|
frontend_port_range_end: 81
|
|
|
|
backend_port: 8080
|
|
|
|
load_balancing_rules:
|
|
|
|
- name: lbrbalancingrule0
|
|
|
|
frontend_ip_configuration: frontendipconf0
|
|
|
|
backend_address_pool: backendaddrpool0
|
|
|
|
frontend_port: 80
|
|
|
|
backend_port: 80
|
|
|
|
probe: prob0
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: assert complex load balancer created
|
|
|
|
assert:
|
|
|
|
that: output.changed
|
|
|
|
|
|
|
|
- name: delete load balancer
|
|
|
|
azure_rm_loadbalancer:
|
|
|
|
resource_group: '{{ resource_group }}'
|
2018-06-12 02:52:07 +00:00
|
|
|
name: "{{ lbname_d }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
state: absent
|
|
|
|
|
2017-08-29 21:29:44 +00:00
|
|
|
- name: cleanup public ip
|
|
|
|
azure_rm_publicipaddress:
|
2018-05-04 05:17:05 +00:00
|
|
|
name: "{{ item }}"
|
2017-08-29 21:29:44 +00:00
|
|
|
resource_group: '{{ resource_group }}'
|
|
|
|
state: absent
|
2018-05-04 05:17:05 +00:00
|
|
|
with_items:
|
2018-05-29 06:22:59 +00:00
|
|
|
- "{{ pipaname }}"
|
|
|
|
- "{{ pipbname }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
|
|
|
|
- name: cleanup subnet
|
|
|
|
azure_rm_subnet:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-29 06:22:59 +00:00
|
|
|
name: "lb{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}sb"
|
|
|
|
virtual_network: "{{ lbvnname }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: cleanup virtual network
|
|
|
|
azure_rm_virtualnetwork:
|
|
|
|
resource_group: "{{ resource_group }}"
|
2018-05-29 06:22:59 +00:00
|
|
|
name: "{{ lbvnname }}"
|
2018-05-04 05:17:05 +00:00
|
|
|
state: absent
|