Skip to content

Commit 3a707e8

Browse files
committed
create service interfaces for cedges on azure
1 parent e1cf967 commit 3a707e8

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed

roles/azure_edges/tasks/azure_cedge_vm.yml

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Machine: "{{ hostname }}"
2020
VPN: "{{ subnet_item.VPN }}"
2121
Subnet: "{{ subnet_item.name }}"
22+
type: "{{ subnet_item.type }}"
2223
loop:
2324
- "{{ mgmt_subnet }}"
2425
- "{{ transport_subnet }}"
@@ -72,24 +73,55 @@
7273
Creator: "{{ az_tag_creator }}"
7374
Organization: "{{ organization_name }}"
7475
VPN: "{{ public_ip_state.state.tags.VPN }}"
76+
type: "{{ public_ip_state.state.tags.type }}"
7577
loop: "{{ public_ip_addresses.results }}"
7678
loop_control:
7779
loop_var: public_ip_state
7880
index_var: my_idx
7981
label: public_ip_state.state.name
8082
register: cedge_nics
8183

84+
- name: "Create private virtual network interface cards"
85+
azure.azcollection.azure_rm_networkinterface:
86+
resource_group: "{{ az_resource_group }}"
87+
name: "nic-{{ hostname }}-vpn-{{ subnet.VPN }}"
88+
virtual_network: "{{ az_virtual_network }}"
89+
subnet_name: "{{ subnet.name }}"
90+
security_group: "{{ az_network_security_group }}"
91+
ip_configurations:
92+
- name: "ipconfig-vpn-{{ subnet.VPN }}"
93+
private_ip_allocation_method: "Dynamic"
94+
tags:
95+
Name: "nic-{{ hostname }}-vpn-{{ subnet.VPN }}"
96+
Creator: "{{ az_tag_creator }}"
97+
Organization: "{{ organization_name }}"
98+
VPN: "{{ subnet.VPN }}"
99+
type: "{{ subnet.type }}"
100+
loop: "{{ az_subnets }}"
101+
loop_control:
102+
loop_var: subnet
103+
index_var: my_idx
104+
label: subnet.name
105+
register: cedge_private_nics
106+
when: subnet.type == "service"
107+
82108
- name: Set az_network_interfaces_cedge fact with a list of interfaces for cedge
83109
ansible.builtin.set_fact:
84110
az_network_interfaces_cedge: "{{ cedge_nics.results | map(attribute='state') | list }}"
111+
az_private_network_interfaces_cedge: "{{ cedge_private_nics.results | selectattr('state', 'defined') | map(attribute='state') | list | default([]) }}"
85112
az_public_ip_addresses_cedge: "{{ public_ip_addresses.results | map(attribute='state') | list }}"
86113

114+
- name: Append to az_network_interfaces_cedge
115+
ansible.builtin.set_fact:
116+
az_network_interfaces_cedge: "{{ az_network_interfaces_cedge + az_private_network_interfaces_cedge }}"
117+
87118
- name: Filter az_network_interfaces_cedge for instance creation. Set az_mgmt_nic and az_transport_nic facts
88119
ansible.builtin.set_fact:
89-
az_mgmt_nic: "{{ az_network_interfaces_cedge | selectattr('tags.VPN', 'equalto', '512') | list | first }}"
90-
az_transport_nic: "{{ az_network_interfaces_cedge | selectattr('tags.VPN', 'equalto', '0') | list | first }}"
91-
az_mgmt_public_ip: "{{ az_public_ip_addresses_cedge | selectattr('tags.VPN', 'equalto', '512') | list | first }}"
92-
az_transport_public_ip: "{{ az_public_ip_addresses_cedge | selectattr('tags.VPN', 'equalto', '0') | list | first }}"
120+
az_mgmt_nic: "{{ az_network_interfaces_cedge | selectattr('tags.type', 'equalto', 'mgmt') | list | first }}"
121+
az_transport_nic: "{{ az_network_interfaces_cedge | selectattr('tags.type', 'equalto', 'transport') | list | first }}"
122+
az_service_nics: "{{ az_network_interfaces_cedge | selectattr('tags.type', 'equalto', 'service') | list | default(omit) }}"
123+
az_mgmt_public_ip: "{{ az_public_ip_addresses_cedge | selectattr('tags.type', 'equalto', 'mgmt') | list | first }}"
124+
az_transport_public_ip: "{{ az_public_ip_addresses_cedge | selectattr('tags.type', 'equalto', 'transport') | list | first }}"
93125

94126
# cedge_mgmt_private_ip
95127
- name: "Set ip addresses cedge facts"
@@ -120,6 +152,18 @@
120152
dest: "{{ generated_userdata_cedge }}"
121153
mode: "0644"
122154

155+
- name: "Set network_interfaces fact"
156+
ansible.builtin.set_fact:
157+
network_interfaces: "{{ [az_mgmt_nic.id, az_transport_nic.id] }}"
158+
159+
- name: "Append service NICs to network_interfaces fact"
160+
ansible.builtin.set_fact:
161+
network_interfaces: "{{ network_interfaces + [service_nic.id] }}"
162+
loop: "{{ az_service_nics }}"
163+
loop_control:
164+
loop_var: service_nic
165+
when: az_service_nics is defined
166+
123167
- name: "Create cedge VM: {{ hostname }}"
124168
azure.azcollection.azure_rm_virtualmachine:
125169
resource_group: "{{ az_resource_group }}"
@@ -136,9 +180,7 @@
136180
ephemeral_os_disk: false
137181
linux_config:
138182
disable_password_authentication: false
139-
network_interfaces:
140-
- "{{ az_mgmt_nic.id }}"
141-
- "{{ az_transport_nic.id }}"
183+
network_interfaces: "{{ network_interfaces }}"
142184
image:
143185
offer: "{{ az_cedge_image_offer }}"
144186
publisher: "{{ az_cedge_image_publisher }}"
@@ -157,6 +199,19 @@
157199
Organization: "{{ organization_name }}"
158200
custom_data: "{{ lookup('file', generated_userdata_cedge) }}"
159201

202+
- name: Set service_interfaces fact
203+
ansible.builtin.set_fact:
204+
service_interfaces: []
205+
206+
- name: Append to service_interfaces
207+
ansible.builtin.set_fact:
208+
service_interfaces: "{{ service_interfaces + [{'addr': nic.ip_configuration.private_ip_address, 'index': index + 2}] }}"
209+
loop: "{{ az_service_nics }}"
210+
loop_control:
211+
loop_var: nic
212+
index_var: index
213+
when: az_service_nics is defined
214+
160215
- name: Store cEdge instance details for deployment_results
161216
ansible.builtin.set_fact:
162217
instance:
@@ -166,6 +221,7 @@
166221
admin_password: "{{ admin_password }}"
167222
mgmt_public_ip: "{{ cedge_mgmt_public_ip }}"
168223
transport_public_ip: "{{ cedge_transport_public_ip }}"
224+
service_interfaces: "{{ service_interfaces | default(omit) }}"
169225
uuid: "{{ uuid }}"
170226
site_id: "{{ site_id }}"
171227
changed_when: true

0 commit comments

Comments
 (0)