Skip to content

Commit 68e79fe

Browse files
committed
proxy: Fix the no_proxy variable
Since 2.29, probably due to a change in ansible templating, the no_proxy variable is rendered as an array of character rather than a string. This results in broken cluster in some case. Eliminate the custom jinja looping to use filters and list flatteing + join instead. Also simplify some things (no separate tasks file, just use `run_once` instead of delegating to localhost)
1 parent ed866e0 commit 68e79fe

File tree

4 files changed

+67
-78
lines changed

4 files changed

+67
-78
lines changed

playbooks/internal_facts.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
- name: Gather and compute network facts
1717
import_role:
1818
name: network_facts
19+
tags:
20+
- always
1921
- name: Gather minimal facts
2022
setup:
2123
gather_subset: '!all'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# Additional string host to inject into NO_PROXY
3+
additional_no_proxy: ""
4+
additional_no_proxy_list: "{{ additional_no_proxy | split(',') }}"
5+
no_proxy_exclude_workers: false
Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,63 @@
11
---
2-
- name: Set facts variables
3-
tags:
4-
- always
5-
block:
6-
- name: Gather node IPs
7-
setup:
8-
gather_subset: '!all,!min,network'
9-
filter: "ansible_default_ip*"
10-
when: ansible_default_ipv4 is not defined or ansible_default_ipv6 is not defined
11-
ignore_unreachable: true
2+
- name: Gather node IPs
3+
setup:
4+
gather_subset: '!all,!min,network'
5+
filter: "ansible_default_ip*"
6+
when: ansible_default_ipv4 is not defined or ansible_default_ipv6 is not defined
7+
ignore_unreachable: true
128

13-
- name: Set computed IPs varables
14-
vars:
15-
fallback_ip: "{{ ansible_default_ipv4.address | d('127.0.0.1') }}"
16-
fallback_ip6: "{{ ansible_default_ipv6.address | d('::1') }}"
17-
# Set 127.0.0.1 as fallback IP if we do not have host facts for host
18-
# ansible_default_ipv4 isn't what you think.
19-
_ipv4: "{{ ip | default(fallback_ip) }}"
20-
_access_ipv4: "{{ access_ip | default(_ipv4) }}"
21-
_ipv6: "{{ ip6 | default(fallback_ip6) }}"
22-
_access_ipv6: "{{ access_ip6 | default(_ipv6) }}"
23-
_access_ips:
24-
- "{{ _access_ipv4 if ipv4_stack }}"
25-
- "{{ _access_ipv6 if ipv6_stack }}"
26-
_ips:
27-
- "{{ _ipv4 if ipv4_stack }}"
28-
- "{{ _ipv6 if ipv6_stack }}"
29-
set_fact:
30-
cacheable: true
31-
main_access_ip: "{{ _access_ipv4 if ipv4_stack else _access_ipv6 }}"
32-
main_ip: "{{ _ipv4 if ipv4_stack else _ipv6 }}"
33-
# Mixed IPs - for dualstack
34-
main_access_ips: "{{ _access_ips | select }}"
35-
main_ips: "{{ _ips | select }}"
9+
- name: Set computed IPs variables
10+
vars:
11+
fallback_ip: "{{ ansible_default_ipv4.address | d('127.0.0.1') }}"
12+
fallback_ip6: "{{ ansible_default_ipv6.address | d('::1') }}"
13+
# Set 127.0.0.1 as fallback IP if we do not have host facts for host
14+
# ansible_default_ipv4 isn't what you think.
15+
_ipv4: "{{ ip | default(fallback_ip) }}"
16+
_access_ipv4: "{{ access_ip | default(_ipv4) }}"
17+
_ipv6: "{{ ip6 | default(fallback_ip6) }}"
18+
_access_ipv6: "{{ access_ip6 | default(_ipv6) }}"
19+
_access_ips:
20+
- "{{ _access_ipv4 if ipv4_stack }}"
21+
- "{{ _access_ipv6 if ipv6_stack }}"
22+
_ips:
23+
- "{{ _ipv4 if ipv4_stack }}"
24+
- "{{ _ipv6 if ipv6_stack }}"
25+
set_fact:
26+
cacheable: true
27+
main_access_ip: "{{ _access_ipv4 if ipv4_stack else _access_ipv6 }}"
28+
main_ip: "{{ _ipv4 if ipv4_stack else _ipv6 }}"
29+
# Mixed IPs - for dualstack
30+
main_access_ips: "{{ _access_ips | select }}"
31+
main_ips: "{{ _ips | select }}"
3632

37-
- name: Set no_proxy
38-
import_tasks: no_proxy.yml
39-
when:
40-
- http_proxy is defined or https_proxy is defined
41-
- no_proxy is not defined
33+
- name: Set no_proxy to all assigned cluster IPs and hostnames
34+
when:
35+
- http_proxy is defined or https_proxy is defined
36+
- no_proxy is not defined
37+
vars:
38+
groups_with_no_proxy:
39+
- kube_control_plane
40+
- "{{ '' if no_proxy_exclude_workers else 'kube_node' }}" # TODO: exclude by a boolean in inventory rather than global variable
41+
- etcd
42+
- calico_rr
43+
hosts_with_no_proxy: "{{ groups_with_no_proxy | select | map('extract', groups) | select('defined') | flatten }}"
44+
_hostnames: "{{ (hosts_with_no_proxy +
45+
(hosts_with_no_proxy | map('extract', hostvars, morekeys=['ansible_hostname'])
46+
| select('defined')))
47+
| unique }}"
48+
no_proxy_prepare:
49+
- "{{ apiserver_loadbalancer_domain_name }}"
50+
- "{{ loadbalancer_apiserver.address }}"
51+
- "{{ hosts_with_no_proxy | map('extract', hostvars, morekeys=['main_access_ip']) }}"
52+
- "{{ _hostnames }}"
53+
- "{{ _hostnames | map('regex_replace', '$', '.' + dns_domain ) }}"
54+
- "{{ additional_no_proxy_list }}"
55+
- 127.0.0.1
56+
- localhost
57+
- "{{ kube_service_subnets }}"
58+
- "{{ kube_pods_subnets }}"
59+
- svc
60+
- "svc.{{ dns_domain }}"
61+
set_fact:
62+
no_proxy: "{{ no_proxy_prepare | flatten | select('defined') | join(',') }}"
63+
run_once: true

roles/network_facts/tasks/no_proxy.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)