|
14 | 14 | # NICs |
15 | 15 | - name: Filter required subnets for instance creation. Set aws_mgmt_subnet and aws_transport_subnet facts |
16 | 16 | ansible.builtin.set_fact: |
17 | | - aws_mgmt_subnet: "{{ aws_subnets_config | selectattr('tags.VPN', 'equalto', '512') | list | first }}" |
18 | | - aws_transport_subnet: "{{ aws_subnets_config | selectattr('tags.VPN', 'equalto', '0') | list | first }}" |
| 17 | + aws_mgmt_subnet: "{{ aws_subnets_config | selectattr('tags.type', 'equalto', 'mgmt') | list | first }}" |
| 18 | + aws_transport_subnet: "{{ aws_subnets_config | selectattr('tags.type', 'equalto', 'transport') | list | first }}" |
19 | 19 |
|
20 | 20 | - name: Create network interfaces for cedge |
21 | 21 | amazon.aws.ec2_eni: |
|
28 | 28 | Creator: "{{ aws_tag_creator }}" |
29 | 29 | Machine: "{{ hostname }}" |
30 | 30 | VPN: "{{ subnet_item.tags.VPN }}" |
| 31 | + type: "{{ subnet_item.tags.type }}" |
31 | 32 | register: network_interfaces_cedge |
32 | | - loop: "{{ [aws_mgmt_subnet, aws_transport_subnet] }}" |
| 33 | + loop: "{{ aws_subnets_config }}" |
33 | 34 | loop_control: |
34 | 35 | loop_var: subnet_item |
35 | 36 | label: "nic-{{ subnet_item.tags.Name }}" |
| 37 | + when: subnet_item.tags.type != "cluster" |
36 | 38 |
|
37 | 39 | - name: Set aws_network_interfaces fact with a list of interfaces for cEdge device |
38 | 40 | ansible.builtin.set_fact: |
39 | 41 | aws_network_interfaces: "{{ network_interfaces_cedge.results | map(attribute='interface') | list }}" |
40 | 42 |
|
41 | 43 | - name: Filter aws_network_interfaces for instance creation. Set aws_mgmt_nic and aws_transport_nic facts |
42 | 44 | ansible.builtin.set_fact: |
43 | | - aws_mgmt_nic: "{{ aws_network_interfaces | selectattr('tags.VPN', 'equalto', '512') | list | first }}" |
44 | | - aws_transport_nic: "{{ aws_network_interfaces | selectattr('tags.VPN', 'equalto', '0') | list | first }}" |
45 | | - |
| 45 | + aws_mgmt_nic: "{{ aws_network_interfaces | selectattr('tags.type', 'equalto', 'mgmt') | list | first }}" |
| 46 | + aws_transport_nic: "{{ aws_network_interfaces | selectattr('tags.type', 'equalto', 'transport') | list | first }}" |
| 47 | + aws_service_nics: "{{ aws_network_interfaces | selectattr('tags.type', 'equalto', 'service') | list | default(omit) }}" |
46 | 48 |
|
47 | 49 | # EIPs |
48 | 50 | - name: Associate EIP with mgmt network interface |
|
57 | 59 | Machine: "{{ hostname }}" |
58 | 60 | VPN: "{{ interface_item.tags.VPN }}" |
59 | 61 | register: eip_edge |
60 | | - loop: "{{ [aws_mgmt_nic, aws_transport_nic] }}" # We do loop starting with mgmt nic, so we know results[0] is mgmt ip |
| 62 | + loop: "{{ [aws_mgmt_nic, aws_transport_nic] + (aws_service_nics | default([])) }}" # We do loop starting with mgmt nic, so we know results[0] is mgmt ip |
61 | 63 | loop_control: |
62 | 64 | loop_var: interface_item |
63 | 65 | label: "eip-for-{{ interface_item.tags.Name }}" |
|
79 | 81 | mode: "0644" |
80 | 82 |
|
81 | 83 |
|
82 | | -# vManage |
| 84 | +- name: Set interfaces fact |
| 85 | + ansible.builtin.set_fact: |
| 86 | + interfaces: |
| 87 | + - id: "{{ aws_mgmt_nic.id }}" |
| 88 | + device_index: 0 |
| 89 | + description: "{{ aws_mgmt_nic.tags.Name }}" |
| 90 | + - id: "{{ aws_transport_nic.id }}" |
| 91 | + device_index: 1 |
| 92 | + description: "{{ aws_transport_nic.tags.Name }}" |
| 93 | + |
| 94 | +- name: Append service interfaces |
| 95 | + ansible.builtin.set_fact: |
| 96 | + interfaces: "{{ interfaces + [{'id': nic.id, 'device_index': index + 2, 'description': nic.tags.Name}] }}" |
| 97 | + loop: "{{ (aws_service_nics | default([])) }}" |
| 98 | + loop_control: |
| 99 | + index_var: index |
| 100 | + loop_var: nic |
| 101 | + when: aws_service_nics is defined |
| 102 | + |
83 | 103 | - name: Launch cedge |
84 | 104 | amazon.aws.ec2_instance: |
85 | 105 | count: 1 |
|
92 | 112 | key_name: "{{ aws_key_name | default('') | bool | ternary(aws_key_name, omit) }}" |
93 | 113 | network: |
94 | 114 | assign_public_ip: false |
95 | | - interfaces: |
96 | | - - id: "{{ aws_mgmt_nic.id }}" |
97 | | - device_index: 0 |
98 | | - description: "{{ aws_mgmt_nic.tags.Name }}" |
99 | | - - id: "{{ aws_transport_nic.id }}" |
100 | | - device_index: 1 |
101 | | - description: "{{ aws_transport_nic.tags.Name }}" |
| 115 | + interfaces: "{{ interfaces }}" |
102 | 116 | name: "{{ hostname }}" |
103 | 117 | tags: |
104 | 118 | Name: "{{ hostname }}" |
|
111 | 125 | delete_on_termination: true |
112 | 126 | register: ec2_cedge |
113 | 127 |
|
| 128 | +- name: Set service_interfaces fact |
| 129 | + ansible.builtin.set_fact: |
| 130 | + service_interfaces: [] |
| 131 | + |
| 132 | +- name: Append to service_interfaces |
| 133 | + ansible.builtin.set_fact: |
| 134 | + service_interfaces: "{{ service_interfaces + [{'addr': nic.private_ip_address, 'index': index + 2}] }}" |
| 135 | + loop: "{{ aws_service_nics }}" |
| 136 | + loop_control: |
| 137 | + loop_var: nic |
| 138 | + index_var: index |
| 139 | + when: aws_service_nics is defined |
| 140 | + |
114 | 141 | - name: Store cEdge instance details for deployment_results |
115 | 142 | ansible.builtin.set_fact: |
116 | 143 | instance: |
|
120 | 147 | admin_password: "{{ admin_password }}" |
121 | 148 | mgmt_public_ip: "{{ eip_edge.results[0].public_ip }}" |
122 | 149 | transport_public_ip: "{{ eip_edge.results[1].public_ip }}" |
| 150 | + service_interfaces: "{{ service_interfaces | default(omit) }}" |
123 | 151 | uuid: "{{ uuid }}" |
| 152 | + site_id: "{{ site_id }}" |
124 | 153 | changed_when: true |
125 | 154 | register: _edge_facts |
126 | 155 | retries: 3 |
|
0 commit comments