2016-11-30 21:06:11 +08:00
|
|
|
---
|
2023-03-31 09:53:49 +08:00
|
|
|
- name: Set os_family fact for other redhat-based operating systems
|
2022-11-07 09:54:16 +08:00
|
|
|
set_fact:
|
|
|
|
ansible_os_family: "RedHat"
|
|
|
|
ansible_distribution_major_version: "8"
|
2023-03-10 14:00:39 +08:00
|
|
|
when: ansible_distribution in redhat_os_family_extensions
|
2022-11-07 09:54:16 +08:00
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check resolvconf
|
2020-07-28 16:39:08 +08:00
|
|
|
command: which resolvconf
|
2016-11-30 21:06:11 +08:00
|
|
|
register: resolvconf
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2016-11-30 21:06:11 +08:00
|
|
|
changed_when: false
|
2017-02-07 02:13:21 +08:00
|
|
|
check_mode: no
|
2016-11-30 21:06:11 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check existence of /etc/resolvconf/resolv.conf.d
|
2021-12-10 06:09:06 +08:00
|
|
|
stat:
|
|
|
|
path: /etc/resolvconf/resolv.conf.d
|
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
|
|
|
failed_when: false
|
|
|
|
register: resolvconfd_path
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check status of /etc/resolv.conf
|
2021-12-10 06:09:06 +08:00
|
|
|
stat:
|
|
|
|
path: /etc/resolv.conf
|
|
|
|
follow: no
|
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
|
|
|
failed_when: false
|
|
|
|
register: resolvconf_stat
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Fetch resolconf
|
2023-08-10 15:57:27 +08:00
|
|
|
when: resolvconf_stat.stat.exists is defined and resolvconf_stat.stat.exists
|
2023-07-26 22:36:22 +08:00
|
|
|
block:
|
2021-12-10 06:09:06 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Get content of /etc/resolv.conf
|
2021-12-10 06:09:06 +08:00
|
|
|
slurp:
|
|
|
|
src: /etc/resolv.conf
|
|
|
|
register: resolvconf_slurp
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Get currently configured nameservers
|
2021-12-10 06:09:06 +08:00
|
|
|
set_fact:
|
2023-10-17 15:45:11 +08:00
|
|
|
configured_nameservers: "{{ resolvconf_slurp.content | b64decode | regex_findall('^nameserver\\s*(\\S*)', multiline=True) | ansible.utils.ipaddr }}"
|
2021-12-10 06:09:06 +08:00
|
|
|
when: resolvconf_slurp.content is defined
|
|
|
|
|
2022-12-02 14:37:54 +08:00
|
|
|
- name: Stop if /etc/resolv.conf not configured nameservers
|
|
|
|
assert:
|
2023-07-05 11:36:54 +08:00
|
|
|
that: configured_nameservers | length>0
|
2022-12-02 14:37:54 +08:00
|
|
|
fail_msg: "nameserver should not empty in /etc/resolv.conf"
|
|
|
|
when:
|
|
|
|
- not ignore_assert_errors
|
|
|
|
- configured_nameservers is defined
|
2023-07-05 11:36:54 +08:00
|
|
|
- not (upstream_dns_servers is defined and upstream_dns_servers | length > 0)
|
2022-12-02 14:37:54 +08:00
|
|
|
- not (disable_host_nameservers | default(false))
|
2023-11-01 10:07:06 +08:00
|
|
|
- dns_mode in ['coredns', 'coredns_dual']
|
2022-12-02 14:37:54 +08:00
|
|
|
|
2022-02-27 02:29:23 +08:00
|
|
|
- name: NetworkManager | Check if host has NetworkManager
|
2023-06-30 17:51:57 +08:00
|
|
|
# noqa command-instead-of-module - Should we use service_facts for this?
|
2022-02-27 02:29:23 +08:00
|
|
|
command: systemctl is-active --quiet NetworkManager.service
|
|
|
|
register: networkmanager_enabled
|
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
check_mode: false
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check systemd-resolved
|
2023-06-30 17:51:57 +08:00
|
|
|
# noqa command-instead-of-module - Should we use service_facts for this?
|
2019-11-06 19:33:52 +08:00
|
|
|
command: systemctl is-active systemd-resolved
|
|
|
|
register: systemd_resolved_enabled
|
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Set default dns if remove_default_searchdomains is false
|
2022-09-24 01:28:26 +08:00
|
|
|
set_fact:
|
|
|
|
default_searchdomains: ["default.svc.{{ dns_domain }}", "svc.{{ dns_domain }}"]
|
2023-07-05 11:36:54 +08:00
|
|
|
when: not remove_default_searchdomains | default() | bool or (remove_default_searchdomains | default() | bool and searchdomains | default([]) | length==0)
|
2022-09-24 01:28:26 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Set dns facts
|
2019-05-16 15:27:43 +08:00
|
|
|
set_fact:
|
2016-11-30 21:06:11 +08:00
|
|
|
resolvconf: >-
|
2021-12-10 06:09:06 +08:00
|
|
|
{%- if resolvconf.rc == 0 and resolvconfd_path.stat.isdir is defined and resolvconfd_path.stat.isdir -%}true{%- else -%}false{%- endif -%}
|
2016-11-30 21:06:11 +08:00
|
|
|
bogus_domains: |-
|
2023-07-05 11:36:54 +08:00
|
|
|
{% for d in default_searchdomains | default([]) + searchdomains | default([]) -%}
|
2019-05-03 05:24:21 +08:00
|
|
|
{{ dns_domain }}.{{ d }}./{{ d }}.{{ d }}./com.{{ d }}./
|
2016-11-30 21:06:11 +08:00
|
|
|
{%- endfor %}
|
2021-05-18 21:41:30 +08:00
|
|
|
cloud_resolver: "{{ ['169.254.169.254'] if cloud_provider is defined and cloud_provider == 'gce' else
|
|
|
|
['169.254.169.253'] if cloud_provider is defined and cloud_provider == 'aws' else
|
|
|
|
[] }}"
|
2016-11-30 21:06:11 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check if kubelet is configured
|
2016-11-30 21:06:11 +08:00
|
|
|
stat:
|
2017-01-19 00:18:47 +08:00
|
|
|
path: "{{ kube_config_dir }}/kubelet.env"
|
2021-02-10 21:36:59 +08:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2017-01-19 00:18:47 +08:00
|
|
|
register: kubelet_configured
|
2016-11-30 21:06:11 +08:00
|
|
|
changed_when: false
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check if early DNS configuration stage
|
2016-11-30 21:06:11 +08:00
|
|
|
set_fact:
|
2022-02-27 02:29:23 +08:00
|
|
|
dns_early: "{{ not kubelet_configured.stat.exists }}"
|
2016-11-30 21:06:11 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Target resolv.conf files
|
2016-11-30 21:06:11 +08:00
|
|
|
set_fact:
|
|
|
|
resolvconffile: /etc/resolv.conf
|
|
|
|
base: >-
|
2023-07-05 11:36:54 +08:00
|
|
|
{%- if resolvconf | bool -%}/etc/resolvconf/resolv.conf.d/base{%- endif -%}
|
2016-11-30 21:06:11 +08:00
|
|
|
head: >-
|
2023-07-05 11:36:54 +08:00
|
|
|
{%- if resolvconf | bool -%}/etc/resolvconf/resolv.conf.d/head{%- endif -%}
|
2021-10-02 00:11:23 +08:00
|
|
|
when: not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] and not is_fedora_coreos
|
2016-11-30 21:06:11 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Target temporary resolvconf cloud init file (Flatcar Container Linux by Kinvolk / Fedora CoreOS)
|
2017-02-18 05:22:34 +08:00
|
|
|
set_fact:
|
|
|
|
resolvconffile: /tmp/resolveconf_cloud_init_conf
|
2021-10-02 00:11:23 +08:00
|
|
|
when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] or is_fedora_coreos
|
2016-11-30 21:06:11 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check if /etc/dhclient.conf exists
|
2017-02-18 05:22:34 +08:00
|
|
|
stat:
|
|
|
|
path: /etc/dhclient.conf
|
2021-02-10 21:36:59 +08:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2016-12-21 19:54:25 +08:00
|
|
|
register: dhclient_stat
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Target dhclient conf file for /etc/dhclient.conf
|
2016-11-30 21:06:11 +08:00
|
|
|
set_fact:
|
2016-12-16 21:49:26 +08:00
|
|
|
dhclientconffile: /etc/dhclient.conf
|
2016-12-21 19:54:25 +08:00
|
|
|
when: dhclient_stat.stat.exists
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check if /etc/dhcp/dhclient.conf exists
|
2017-02-18 05:22:34 +08:00
|
|
|
stat:
|
|
|
|
path: /etc/dhcp/dhclient.conf
|
2021-02-10 21:36:59 +08:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2017-01-14 00:14:57 +08:00
|
|
|
register: dhcp_dhclient_stat
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Target dhclient conf file for /etc/dhcp/dhclient.conf
|
2016-12-21 19:54:25 +08:00
|
|
|
set_fact:
|
|
|
|
dhclientconffile: /etc/dhcp/dhclient.conf
|
2017-01-14 00:14:57 +08:00
|
|
|
when: dhcp_dhclient_stat.stat.exists
|
2016-12-21 19:54:25 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Target dhclient hook file for Red Hat family
|
2016-12-21 19:54:25 +08:00
|
|
|
set_fact:
|
2016-11-30 21:06:11 +08:00
|
|
|
dhclienthookfile: /etc/dhcp/dhclient.d/zdnsupdate.sh
|
|
|
|
when: ansible_os_family == "RedHat"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Target dhclient hook file for Debian family
|
2016-11-30 21:06:11 +08:00
|
|
|
set_fact:
|
|
|
|
dhclienthookfile: /etc/dhcp/dhclient-exit-hooks.d/zdnsupdate
|
|
|
|
when: ansible_os_family == "Debian"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Generate search domains to resolvconf
|
2016-11-30 21:06:11 +08:00
|
|
|
set_fact:
|
|
|
|
searchentries:
|
2023-07-05 11:36:54 +08:00
|
|
|
search {{ (default_searchdomains | default([]) + searchdomains | default([])) | join(' ') }}
|
2016-11-30 21:06:11 +08:00
|
|
|
domainentry:
|
|
|
|
domain {{ dns_domain }}
|
|
|
|
supersede_search:
|
2023-07-05 11:36:54 +08:00
|
|
|
supersede domain-search "{{ (default_searchdomains | default([]) + searchdomains | default([])) | join('", "') }}";
|
2016-11-30 21:06:11 +08:00
|
|
|
supersede_domain:
|
|
|
|
supersede domain-name "{{ dns_domain }}";
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Pick coredns cluster IP or default resolver
|
2016-11-30 21:06:11 +08:00
|
|
|
set_fact:
|
2019-04-02 03:32:34 +08:00
|
|
|
coredns_server: |-
|
2023-07-05 11:36:54 +08:00
|
|
|
{%- if dns_mode == 'coredns' and not dns_early | bool -%}
|
|
|
|
{{ [skydns_server] }}
|
|
|
|
{%- elif dns_mode == 'coredns_dual' and not dns_early | bool -%}
|
|
|
|
{{ [skydns_server] + [skydns_server_secondary] }}
|
|
|
|
{%- elif dns_mode == 'manual' and not dns_early | bool -%}
|
|
|
|
{{ (manual_dns_server.split(',') | list) }}
|
|
|
|
{%- elif dns_mode == 'none' and not dns_early | bool -%}
|
2020-10-29 16:04:58 +08:00
|
|
|
[]
|
2023-07-05 11:36:54 +08:00
|
|
|
{%- elif dns_early | bool -%}
|
|
|
|
{{ upstream_dns_servers | default([]) }}
|
2016-11-30 21:06:11 +08:00
|
|
|
{%- endif -%}
|
|
|
|
|
2022-02-27 02:29:23 +08:00
|
|
|
# This task should only run after cluster/nodelocal DNS is up, otherwise all DNS lookups will timeout
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Generate nameservers for resolvconf, including cluster DNS
|
2016-11-30 21:06:11 +08:00
|
|
|
set_fact:
|
2022-02-27 02:29:23 +08:00
|
|
|
nameserverentries: |-
|
2023-07-05 11:36:54 +08:00
|
|
|
{{ (([nodelocaldns_ip] if enable_nodelocaldns else []) + (coredns_server | d([]) if not enable_nodelocaldns else []) + nameservers | d([]) + cloud_resolver | d([]) + (configured_nameservers | d([]) if not disable_host_nameservers | d() | bool else [])) | unique | join(',') }}
|
2024-08-06 18:38:51 +08:00
|
|
|
dhclient_supersede_nameserver_entries_list: |-
|
|
|
|
{{ (([nodelocaldns_ip] if enable_nodelocaldns else []) + (coredns_server | d([]) if not enable_nodelocaldns else []) + nameservers | d([]) + cloud_resolver | d([]) + (configured_nameservers | d([]) if not disable_host_nameservers | d() | bool else [])) | unique }}
|
2022-02-27 02:29:23 +08:00
|
|
|
when: not dns_early or dns_late
|
|
|
|
|
|
|
|
# This task should run instead of the above task when cluster/nodelocal DNS hasn't
|
|
|
|
# been deployed yet (like scale.yml/cluster.yml) or when it's down (reset.yml)
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Generate nameservers for resolvconf, not including cluster DNS
|
2022-02-27 02:29:23 +08:00
|
|
|
set_fact:
|
|
|
|
nameserverentries: |-
|
2023-07-05 11:36:54 +08:00
|
|
|
{{ (nameservers | d([]) + cloud_resolver | d([]) + configured_nameservers | d([])) | unique | join(',') }}
|
2024-08-06 18:38:51 +08:00
|
|
|
dhclient_supersede_nameserver_entries_list: |-
|
|
|
|
{{ (nameservers | d([]) + cloud_resolver | d([])) | unique }}
|
2022-02-27 02:29:23 +08:00
|
|
|
when: dns_early and not dns_late
|
2018-08-23 22:51:52 +08:00
|
|
|
|
2024-08-06 18:38:51 +08:00
|
|
|
- name: Generate supersede_nameserver from dhclient_supersede_nameserver_entries_list
|
|
|
|
set_fact:
|
|
|
|
supersede_nameserver: |-
|
|
|
|
{%- if dhclient_supersede_nameserver_entries_list | length > 0 -%}
|
|
|
|
supersede domain-name-servers {{ dhclient_supersede_nameserver_entries_list | join(', ') }};
|
|
|
|
{%- endif -%}
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Set etcd vars if using kubeadm mode
|
2019-06-21 02:12:51 +08:00
|
|
|
set_fact:
|
|
|
|
etcd_cert_dir: "{{ kube_cert_dir }}"
|
|
|
|
kube_etcd_cacert_file: "etcd/ca.crt"
|
|
|
|
kube_etcd_cert_file: "apiserver-etcd-client.crt"
|
|
|
|
kube_etcd_key_file: "apiserver-etcd-client.key"
|
|
|
|
when:
|
2022-02-23 00:53:16 +08:00
|
|
|
- etcd_deployment_type == "kubeadm"
|
2019-07-31 03:00:10 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check /usr readonly
|
2019-07-31 03:00:10 +08:00
|
|
|
stat:
|
|
|
|
path: "/usr"
|
2021-02-10 21:36:59 +08:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2019-07-31 03:00:10 +08:00
|
|
|
register: usr
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Set alternate flexvolume path
|
2019-07-31 03:00:10 +08:00
|
|
|
set_fact:
|
|
|
|
kubelet_flexvolumes_plugins_dir: /var/lib/kubelet/volumeplugins
|
|
|
|
when: not usr.stat.writeable
|