|
19 | 19 | Machine: "{{ hostname }}" |
20 | 20 | VPN: "{{ subnet_item.VPN }}" |
21 | 21 | Subnet: "{{ subnet_item.name }}" |
| 22 | + type: "{{ subnet_item.type }}" |
22 | 23 | loop: |
23 | 24 | - "{{ mgmt_subnet }}" |
24 | 25 | - "{{ transport_subnet }}" |
|
72 | 73 | Creator: "{{ az_tag_creator }}" |
73 | 74 | Organization: "{{ organization_name }}" |
74 | 75 | VPN: "{{ public_ip_state.state.tags.VPN }}" |
| 76 | + type: "{{ public_ip_state.state.tags.type }}" |
75 | 77 | loop: "{{ public_ip_addresses.results }}" |
76 | 78 | loop_control: |
77 | 79 | loop_var: public_ip_state |
78 | 80 | index_var: my_idx |
79 | 81 | label: public_ip_state.state.name |
80 | 82 | register: cedge_nics |
81 | 83 |
|
| 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 | + |
82 | 108 | - name: Set az_network_interfaces_cedge fact with a list of interfaces for cedge |
83 | 109 | ansible.builtin.set_fact: |
84 | 110 | 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([]) }}" |
85 | 112 | az_public_ip_addresses_cedge: "{{ public_ip_addresses.results | map(attribute='state') | list }}" |
86 | 113 |
|
| 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 | + |
87 | 118 | - name: Filter az_network_interfaces_cedge for instance creation. Set az_mgmt_nic and az_transport_nic facts |
88 | 119 | 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 }}" |
93 | 125 |
|
94 | 126 | # cedge_mgmt_private_ip |
95 | 127 | - name: "Set ip addresses cedge facts" |
|
120 | 152 | dest: "{{ generated_userdata_cedge }}" |
121 | 153 | mode: "0644" |
122 | 154 |
|
| 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 | + |
123 | 167 | - name: "Create cedge VM: {{ hostname }}" |
124 | 168 | azure.azcollection.azure_rm_virtualmachine: |
125 | 169 | resource_group: "{{ az_resource_group }}" |
|
136 | 180 | ephemeral_os_disk: false |
137 | 181 | linux_config: |
138 | 182 | disable_password_authentication: false |
139 | | - network_interfaces: |
140 | | - - "{{ az_mgmt_nic.id }}" |
141 | | - - "{{ az_transport_nic.id }}" |
| 183 | + network_interfaces: "{{ network_interfaces }}" |
142 | 184 | image: |
143 | 185 | offer: "{{ az_cedge_image_offer }}" |
144 | 186 | publisher: "{{ az_cedge_image_publisher }}" |
|
157 | 199 | Organization: "{{ organization_name }}" |
158 | 200 | custom_data: "{{ lookup('file', generated_userdata_cedge) }}" |
159 | 201 |
|
| 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 | + |
160 | 215 | - name: Store cEdge instance details for deployment_results |
161 | 216 | ansible.builtin.set_fact: |
162 | 217 | instance: |
|
166 | 221 | admin_password: "{{ admin_password }}" |
167 | 222 | mgmt_public_ip: "{{ cedge_mgmt_public_ip }}" |
168 | 223 | transport_public_ip: "{{ cedge_transport_public_ip }}" |
| 224 | + service_interfaces: "{{ service_interfaces | default(omit) }}" |
| 225 | + uuid: "{{ uuid }}" |
| 226 | + site_id: "{{ site_id }}" |
169 | 227 | changed_when: true |
170 | 228 | notify: Show deployment_facts |
171 | 229 |
|
|
0 commit comments