|
1 | 1 | --- |
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 |
12 | 8 |
|
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 }}" |
36 | 32 |
|
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 if loadbalancer_apiserver is defined else '' }}" |
| 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 | select | flatten | unique | join(',') }}" |
| 63 | + run_once: true |
0 commit comments