Skip to content

Commit 54f339d

Browse files
committed
Launch Azure Edges in multiple Azure regions
1 parent a131dc0 commit 54f339d

File tree

6 files changed

+40
-5
lines changed

6 files changed

+40
-5
lines changed

roles/azure_edges/tasks/azure_cedge_vm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929

3030
- name: "Get info about NSG: {{ az_network_security_group }}"
3131
azure.azcollection.azure_rm_securitygroup_info:
32-
resource_group: "{{ az_resource_group }}"
32+
resource_group: "{{ az_default_resource_group }}"
3333
name: "{{ az_network_security_group }}"
3434
register: az_res_gr
3535

3636
- name: "Extend Network Security Group for machine, NSG: {{ az_network_security_group }}"
3737
azure.azcollection.azure_rm_securitygroup:
38-
resource_group: "{{ az_resource_group }}"
38+
resource_group: "{{ az_default_resource_group }}"
3939
name: "{{ az_network_security_group }}"
4040
rules:
4141
- name: "{{ public_ip_state.state.name }}"

roles/azure_edges/tasks/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
ansible.builtin.set_fact:
4545
deployment_facts:
4646
deployed_edge_instances: []
47+
az_default_location: "{{ az_location }}"
48+
az_default_resource_group: "{{ az_resource_group }}"
4749

4850
- name: Create VM instance - cEdge (C8000V)
4951
ansible.builtin.include_tasks: azure_cedge_vm.yml
@@ -54,10 +56,18 @@
5456
vbond: "{{ instance_item.vbond }}"
5557
system_ip: "{{ instance_item.system_ip }}"
5658
site_id: "{{ instance_item.site_id }}"
59+
wan_edges_item: "{{ wan_edges | default([]) | json_query('[?uuid==`'~instance_item.uuid~'`] | [0]') }}"
60+
is_in_default_location: "{{ 'az_location' not in wan_edges_item or wan_edges_item['az_location'] == az_default_location }}"
61+
az_resource_group: "{{ az_default_resource_group if is_in_default_location else az_resources_prefix~'-'~wan_edges_item['az_location']~'-rg' }}"
5762
loop: "{{ edge_instances }}"
5863
loop_control:
5964
loop_var: instance_item
60-
when: edge_instances is defined and (instance_item.hostname not in instances_info or not instances_info[instance_item.hostname])
65+
when:
66+
- edge_instances is defined
67+
- instance_item.hostname not in instances_info or not instances_info[instance_item.hostname]
68+
- >
69+
wan_edges is not defined
70+
or wan_edges | json_query('[?uuid==`'~instance_item['uuid']~'`] | [?!contains(keys(@), `foreign`) || !foreign]')
6171
6272
- name: Extract deployment facts
6373
ansible.builtin.include_role:

roles/azure_network_infrastructure/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ organization_name: null # has to be set by user
1212
az_location: null
1313
az_tag_creator: "{{ organization_name }}"
1414
az_resources_prefix: "{{ organization_name }}" # default to organization_name, but user should have option to modify
15+
az_all_locations: "{{ [az_location] + wan_edges | default([]) | json_query('[?az_location].az_location') | unique }}"
1516

1617
# Resource group
1718
az_resource_group: "{{ az_resources_prefix }}-rg"

roles/azure_network_infrastructure/tasks/main.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,18 @@
2222
state: directory
2323
mode: "0755"
2424

25+
- name: Save default az_location
26+
set_fact:
27+
az_default_location: "{{ az_location }}"
28+
az_default_resource_group: "{{ az_resources_prefix }}-rg"
29+
2530
- name: "Network resources for SD-WAN machines"
26-
ansible.builtin.include_tasks: azure_network_infrastructure.yml
31+
ansible.builtin.include_tasks:
32+
file: azure_network_infrastructure.yml
33+
apply:
34+
vars:
35+
az_resource_group: "{{ az_default_resource_group if item == az_default_location else az_resources_prefix~'-'~item~'-rg' }}"
36+
az_location: "{{ item }}"
37+
loop: "{{ az_all_locations }}"
38+
loop_control:
39+
label: "{{ item }}"

roles/azure_teardown/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ wait_for_teardown: true # if set to false, teardown playbook will finish witout
1414
az_location: null
1515
az_tag_creator: "{{ organization_name }}"
1616
az_resources_prefix: "{{ organization_name }}" # default to organization_name, but user should have option to modify
17+
az_all_locations: "{{ [az_location] + wan_edges | default([]) | json_query('[?az_location].az_location') | unique }}"
1718

1819
# Resource group
1920
az_resource_group: "{{ az_resources_prefix }}-rg"

roles/azure_teardown/tasks/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
- name: "Replace underscores with hyphens in the az_resources_prefix string"
1010
ansible.builtin.set_fact:
1111
az_resources_prefix: "{{ az_resources_prefix | replace('_', '-') }}"
12+
az_default_location: "{{ az_location }}"
13+
az_default_resource_group: "{{ az_resources_prefix }}-rg"
1214

1315
- name: Remove Azure Resource Group and wait for teardown completion
14-
ansible.builtin.include_tasks: az_teardown_rg.yml
16+
ansible.builtin.include_tasks:
17+
file: az_teardown_rg.yml
18+
apply:
19+
vars:
20+
az_resource_group: "{{ az_default_resource_group if item == az_default_location else az_resources_prefix~'-'~item~'-rg' }}"
21+
az_location: "{{ item }}"
22+
loop: "{{ az_all_locations }}"
23+
loop_control:
24+
label: "{{ item }}"

0 commit comments

Comments
 (0)