Skip to content

Commit a4426f9

Browse files
eduolivaresclaude
andcommitted
Fix BGP registry IP route collection for multi-datacenter deployments
The original implementation attempted to run getent directly in the task with delegate_to using an undefined loop variable, causing task failures. This fix properly delegates getent execution to each overcloud VM and accumulates the resolved IPs across all VMs. This is necessary because VMs in different racks/datacenters may use different DNS servers, resulting in different IP resolutions for the same registry domains. Changes: - Extract getent logic into separate task file (getent_registry_ips_bgp.yml) - Run getent from each VM via include_tasks with proper delegation - Accumulate IPs using set_fact to preserve results across all VMs - Simplify IP list generation in both prepare_overcloud.yml and prepare_undercloud.yml to use the accumulated list The accumulated IP list ensures routes are added for all possible registry IPs as resolved from each datacenter's DNS server. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 018705c commit a4426f9

File tree

4 files changed

+57
-41
lines changed

4 files changed

+57
-41
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
# Copyright Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Obtain IPs whose routes need to be added to the undercloud (bgp)
18+
ansible.builtin.getent:
19+
database: ahosts
20+
key: "{{ item }}"
21+
register: _current_vm_getent
22+
loop:
23+
- registry.redhat.io
24+
- cdn.redhat.com
25+
- access.redhat.com
26+
- cdn01.quay.io
27+
28+
- name: Accumulate IPs from this VM
29+
ansible.builtin.set_fact:
30+
_accumulated_ips: >-
31+
{{
32+
_accumulated_ips | default([]) +
33+
(
34+
_current_vm_getent.results |
35+
map(attribute='ansible_facts.getent_ahosts') |
36+
map('dict2items') |
37+
flatten |
38+
map(attribute='key') |
39+
reject('match', '.*:.*') |
40+
list
41+
)
42+
}}

roles/adoption_osp_deploy/tasks/prepare_overcloud.yml

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,14 @@
197197

198198
- name: Obtain IPs whose routes need to be added to the undercloud (bgp)
199199
when: bgp
200-
delegate_to: "{{ overcloud_vm }}"
201-
ansible.builtin.getent:
202-
database: ahosts
203-
key: "{{ item }}"
204-
register: _ips_for_oc_routes_getent
205-
loop:
206-
- registry.redhat.io
207-
- cdn.redhat.com
208-
- access.redhat.com
209-
- cdn01.quay.io
200+
ansible.builtin.include_tasks: getent_registry_ips_bgp.yml
201+
args:
202+
apply:
203+
delegate_to: "{{ _vm }}"
204+
loop: "{{ _tripleo_nodes_stack[_overcloud_name] }}"
205+
loop_control:
206+
loop_var: _vm
207+
pause: 1
210208

211209
- name: Generate os-net-config file for overcloud nodes (bgp)
212210
become: true
@@ -215,17 +213,7 @@
215213
_node_net: "{{ cifmw_networking_env_definition.instances[overcloud_vm] }}"
216214
_dns_server: "{{ _ctlplane_net.[dns_version|default('dns_v4')] }}"
217215
_interface_mtu: 1500
218-
_ips_for_oc_routes_list: >-
219-
{{
220-
_ips_for_oc_routes_getent.results |
221-
map(attribute='ansible_facts.getent_ahosts') |
222-
map('dict2items') |
223-
flatten |
224-
map(attribute='key') |
225-
reject('match', '.*:.*') |
226-
list |
227-
unique
228-
}}
216+
_ips_for_oc_routes_list: "{{ _accumulated_ips | unique }}"
229217
vms:
230218
osp-r0-compute-0:
231219
ctlplane: '192.168.122.100'

roles/adoption_osp_deploy/tasks/prepare_undercloud.yml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,7 @@
128128

129129
- name: Obtain IPs whose routes need to be added to the undercloud (bgp)
130130
when: bgp
131-
ansible.builtin.getent:
132-
database: ahosts
133-
key: "{{ item }}"
134-
register: _ips_for_uc_routes_getent
135-
loop:
136-
- registry.redhat.io
137-
- cdn.redhat.com
138-
- access.redhat.com
139-
- cdn01.quay.io
131+
ansible.builtin.include_tasks: getent_registry_ips_bgp.yml
140132

141133
- name: Generate os-net-config file (bgp)
142134
when: bgp
@@ -151,17 +143,7 @@
151143
_gateway_ip: "{{ _ctlplane_net[gw_version|default('gw_v4')] }}"
152144
_interface_mtu: "{{ _undercloud_net.networks.ctlplaner0.mtu }}"
153145
_ctlplane_cidr: "{{ _undercloud_net.networks.ctlplaner0[prefix_length_version|default('prefix_length_v4')] }}"
154-
_ips_for_uc_routes_list: >-
155-
{{
156-
_ips_for_uc_routes_getent.results |
157-
map(attribute='ansible_facts.getent_ahosts') |
158-
map('dict2items') |
159-
flatten |
160-
map(attribute='key') |
161-
reject('match', '.*:.*') |
162-
list |
163-
unique
164-
}}
146+
_ips_for_uc_routes_list: "{{ _accumulated_ips | unique }}"
165147
ansible.builtin.template:
166148
src: "os_net_config_undercloud_bgp.yml.j2"
167149
dest: /etc/os-net-config/tripleo_config.yaml

roles/adoption_osp_deploy/templates/os_net_config_overcloud_bgp.yml.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ network_config:
66
use_dhcp: true
77
defroute: false
88
routes:
9+
- ip_netmask: 10.0.0.0/8
10+
next_hop: 192.168.111.1
11+
- ip_netmask: 23.0.0.0/8
12+
next_hop: 192.168.111.1
913
{% for _ip in _ips_for_oc_routes_list %}
1014
- ip_netmask: {{ _ip }}/32
1115
next_hop: 192.168.111.1

0 commit comments

Comments
 (0)