2016-11-30 13:06:11 +00:00
|
|
|
---
|
2020-08-28 09:28:53 +00:00
|
|
|
- name: Force binaries directory for Flatcar Container Linux by Kinvolk
|
2018-08-23 14:51:52 +00:00
|
|
|
set_fact:
|
|
|
|
bin_dir: "/opt/bin"
|
2021-10-01 16:11:23 +00:00
|
|
|
when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
|
2018-08-23 14:51:52 +00:00
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
|
2020-03-17 21:31:27 +00:00
|
|
|
- name: check if booted with ostree
|
2018-08-23 14:51:52 +00:00
|
|
|
stat:
|
|
|
|
path: /run/ostree-booted
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2018-08-23 14:51:52 +00:00
|
|
|
register: ostree
|
|
|
|
|
2020-03-17 10:12:21 +00:00
|
|
|
- name: set is_fedora_coreos
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/os-release
|
|
|
|
line: "VARIANT_ID=coreos"
|
|
|
|
state: present
|
|
|
|
check_mode: yes
|
|
|
|
register: os_variant_coreos
|
2020-06-16 07:24:03 +00:00
|
|
|
changed_when: false
|
2020-03-17 10:12:21 +00:00
|
|
|
|
|
|
|
- name: set is_fedora_coreos
|
|
|
|
set_fact:
|
|
|
|
is_fedora_coreos: "{{ ostree.stat.exists and os_variant_coreos is not changed }}"
|
|
|
|
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: check resolvconf
|
|
|
|
command: which resolvconf
|
2016-11-30 13:06:11 +00:00
|
|
|
register: resolvconf
|
2016-12-27 11:38:54 +00:00
|
|
|
failed_when: false
|
2016-11-30 13:06:11 +00:00
|
|
|
changed_when: false
|
2017-02-06 18:13:21 +00:00
|
|
|
check_mode: no
|
2016-11-30 13:06:11 +00:00
|
|
|
|
2021-12-09 22:09:06 +00:00
|
|
|
- name: check existence of /etc/resolvconf/resolv.conf.d
|
|
|
|
stat:
|
|
|
|
path: /etc/resolvconf/resolv.conf.d
|
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
|
|
|
failed_when: false
|
|
|
|
register: resolvconfd_path
|
|
|
|
|
|
|
|
- name: check status of /etc/resolv.conf
|
|
|
|
stat:
|
|
|
|
path: /etc/resolv.conf
|
|
|
|
follow: no
|
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
|
|
|
failed_when: false
|
|
|
|
register: resolvconf_stat
|
|
|
|
|
|
|
|
- block:
|
|
|
|
|
|
|
|
- name: get content of /etc/resolv.conf
|
|
|
|
slurp:
|
|
|
|
src: /etc/resolv.conf
|
|
|
|
register: resolvconf_slurp
|
|
|
|
|
|
|
|
- name: get currently configured nameservers
|
|
|
|
set_fact:
|
|
|
|
configured_nameservers: "{{ resolvconf_slurp.content | b64decode | regex_findall('\\s*nameserver\\s*(.*)') | ipaddr }}"
|
|
|
|
when: resolvconf_slurp.content is defined
|
|
|
|
|
|
|
|
when: resolvconf_stat.stat.exists is defined and resolvconf_stat.stat.exists
|
|
|
|
|
2022-02-26 18:29:23 +00:00
|
|
|
- name: NetworkManager | Check if host has NetworkManager
|
|
|
|
# noqa 303 Should we use service_facts for this?
|
|
|
|
command: systemctl is-active --quiet NetworkManager.service
|
|
|
|
register: networkmanager_enabled
|
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
check_mode: false
|
|
|
|
|
2020-08-31 10:30:20 +00:00
|
|
|
- name: check systemd-resolved
|
|
|
|
# noqa 303 Should we use service_facts for this?
|
2019-11-06 11:33:52 +00:00
|
|
|
command: systemctl is-active systemd-resolved
|
|
|
|
register: systemd_resolved_enabled
|
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
|
2022-09-23 17:28:26 +00:00
|
|
|
- name: set default dns if remove_default_searchdomains is false
|
|
|
|
set_fact:
|
|
|
|
default_searchdomains: ["default.svc.{{ dns_domain }}", "svc.{{ dns_domain }}"]
|
|
|
|
when: not remove_default_searchdomains|default()|bool or (remove_default_searchdomains|default()|bool and searchdomains|default([])|length==0)
|
|
|
|
|
2019-05-16 07:27:43 +00:00
|
|
|
- name: set dns facts
|
|
|
|
set_fact:
|
2016-11-30 13:06:11 +00:00
|
|
|
resolvconf: >-
|
2021-12-09 22:09:06 +00:00
|
|
|
{%- if resolvconf.rc == 0 and resolvconfd_path.stat.isdir is defined and resolvconfd_path.stat.isdir -%}true{%- else -%}false{%- endif -%}
|
2016-11-30 13:06:11 +00:00
|
|
|
bogus_domains: |-
|
2022-09-23 17:28:26 +00:00
|
|
|
{% for d in default_searchdomains|default([]) + searchdomains|default([]) -%}
|
2019-05-02 21:24:21 +00:00
|
|
|
{{ dns_domain }}.{{ d }}./{{ d }}.{{ d }}./com.{{ d }}./
|
2016-11-30 13:06:11 +00:00
|
|
|
{%- endfor %}
|
2021-05-18 13:41:30 +00: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 13:06:11 +00:00
|
|
|
|
2017-01-18 16:18:47 +00:00
|
|
|
- name: check if kubelet is configured
|
2016-11-30 13:06:11 +00:00
|
|
|
stat:
|
2017-01-18 16:18:47 +00:00
|
|
|
path: "{{ kube_config_dir }}/kubelet.env"
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2017-01-18 16:18:47 +00:00
|
|
|
register: kubelet_configured
|
2016-11-30 13:06:11 +00:00
|
|
|
changed_when: false
|
|
|
|
|
|
|
|
- name: check if early DNS configuration stage
|
|
|
|
set_fact:
|
2022-02-26 18:29:23 +00:00
|
|
|
dns_early: "{{ not kubelet_configured.stat.exists }}"
|
2016-11-30 13:06:11 +00:00
|
|
|
|
|
|
|
- name: target resolv.conf files
|
|
|
|
set_fact:
|
|
|
|
resolvconffile: /etc/resolv.conf
|
|
|
|
base: >-
|
|
|
|
{%- if resolvconf|bool -%}/etc/resolvconf/resolv.conf.d/base{%- endif -%}
|
|
|
|
head: >-
|
|
|
|
{%- if resolvconf|bool -%}/etc/resolvconf/resolv.conf.d/head{%- endif -%}
|
2021-10-01 16:11:23 +00:00
|
|
|
when: not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] and not is_fedora_coreos
|
2016-11-30 13:06:11 +00:00
|
|
|
|
2020-08-28 09:28:53 +00:00
|
|
|
- name: target temporary resolvconf cloud init file (Flatcar Container Linux by Kinvolk / Fedora CoreOS)
|
2017-02-17 21:22:34 +00:00
|
|
|
set_fact:
|
|
|
|
resolvconffile: /tmp/resolveconf_cloud_init_conf
|
2021-10-01 16:11:23 +00:00
|
|
|
when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"] or is_fedora_coreos
|
2016-11-30 13:06:11 +00:00
|
|
|
|
2016-12-21 11:54:25 +00:00
|
|
|
- name: check if /etc/dhclient.conf exists
|
2017-02-17 21:22:34 +00:00
|
|
|
stat:
|
|
|
|
path: /etc/dhclient.conf
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2016-12-21 11:54:25 +00:00
|
|
|
register: dhclient_stat
|
|
|
|
|
|
|
|
- name: target dhclient conf file for /etc/dhclient.conf
|
2016-11-30 13:06:11 +00:00
|
|
|
set_fact:
|
2016-12-16 13:49:26 +00:00
|
|
|
dhclientconffile: /etc/dhclient.conf
|
2016-12-21 11:54:25 +00:00
|
|
|
when: dhclient_stat.stat.exists
|
|
|
|
|
2017-01-13 16:14:57 +00:00
|
|
|
- name: check if /etc/dhcp/dhclient.conf exists
|
2017-02-17 21:22:34 +00:00
|
|
|
stat:
|
|
|
|
path: /etc/dhcp/dhclient.conf
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2017-01-13 16:14:57 +00:00
|
|
|
register: dhcp_dhclient_stat
|
|
|
|
|
2016-12-21 11:54:25 +00:00
|
|
|
- name: target dhclient conf file for /etc/dhcp/dhclient.conf
|
|
|
|
set_fact:
|
|
|
|
dhclientconffile: /etc/dhcp/dhclient.conf
|
2017-01-13 16:14:57 +00:00
|
|
|
when: dhcp_dhclient_stat.stat.exists
|
2016-12-21 11:54:25 +00:00
|
|
|
|
|
|
|
- name: target dhclient hook file for Red Hat family
|
|
|
|
set_fact:
|
2016-11-30 13:06:11 +00:00
|
|
|
dhclienthookfile: /etc/dhcp/dhclient.d/zdnsupdate.sh
|
|
|
|
when: ansible_os_family == "RedHat"
|
|
|
|
|
2016-12-21 11:54:25 +00:00
|
|
|
- name: target dhclient hook file for Debian family
|
2016-11-30 13:06:11 +00:00
|
|
|
set_fact:
|
|
|
|
dhclienthookfile: /etc/dhcp/dhclient-exit-hooks.d/zdnsupdate
|
|
|
|
when: ansible_os_family == "Debian"
|
|
|
|
|
|
|
|
- name: generate search domains to resolvconf
|
|
|
|
set_fact:
|
|
|
|
searchentries:
|
2022-09-23 17:28:26 +00:00
|
|
|
search {{ (default_searchdomains|default([]) + searchdomains|default([])) | join(' ') }}
|
2016-11-30 13:06:11 +00:00
|
|
|
domainentry:
|
|
|
|
domain {{ dns_domain }}
|
|
|
|
supersede_search:
|
2022-09-23 17:28:26 +00:00
|
|
|
supersede domain-search "{{ (default_searchdomains|default([]) + searchdomains|default([])) | join('", "') }}";
|
2016-11-30 13:06:11 +00:00
|
|
|
supersede_domain:
|
|
|
|
supersede domain-name "{{ dns_domain }}";
|
|
|
|
|
2019-04-01 19:32:34 +00:00
|
|
|
- name: pick coredns cluster IP or default resolver
|
2016-11-30 13:06:11 +00:00
|
|
|
set_fact:
|
2019-04-01 19:32:34 +00:00
|
|
|
coredns_server: |-
|
|
|
|
{%- if dns_mode == 'coredns' and not dns_early|bool -%}
|
2019-12-02 16:41:05 +00:00
|
|
|
{{ [ skydns_server ] }}
|
2018-03-13 11:00:05 +00:00
|
|
|
{%- elif dns_mode == 'coredns_dual' and not dns_early|bool -%}
|
2019-12-02 16:41:05 +00:00
|
|
|
{{ [ skydns_server ] + [ skydns_server_secondary ] }}
|
2018-01-23 13:28:42 +00:00
|
|
|
{%- elif dns_mode == 'manual' and not dns_early|bool -%}
|
2019-12-02 16:41:05 +00:00
|
|
|
{{ ( manual_dns_server.split(',') | list) }}
|
2020-10-29 08:04:58 +00:00
|
|
|
{%- elif dns_mode == 'none' and not dns_early|bool -%}
|
|
|
|
[]
|
2016-11-30 13:06:11 +00:00
|
|
|
{%- elif dns_early|bool -%}
|
2016-12-16 10:29:08 +00:00
|
|
|
{{ upstream_dns_servers|default([]) }}
|
2016-11-30 13:06:11 +00:00
|
|
|
{%- endif -%}
|
|
|
|
|
2022-02-26 18:29:23 +00:00
|
|
|
# This task should only run after cluster/nodelocal DNS is up, otherwise all DNS lookups will timeout
|
|
|
|
- name: generate nameservers for resolvconf, including cluster DNS
|
2016-11-30 13:06:11 +00:00
|
|
|
set_fact:
|
2022-02-26 18:29:23 +00:00
|
|
|
nameserverentries: |-
|
2022-10-04 13:22:17 +00: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(',') }}
|
2016-12-13 14:43:05 +00:00
|
|
|
supersede_nameserver:
|
2022-09-26 03:19:44 +00:00
|
|
|
supersede domain-name-servers {{ ( ( [nodelocaldns_ip] if enable_nodelocaldns else []) + coredns_server|d([]) + nameservers|d([]) + cloud_resolver|d([])) | unique | join(', ') }};
|
2022-02-26 18:29:23 +00: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)
|
|
|
|
- name: generate nameservers for resolvconf, not including cluster DNS
|
|
|
|
set_fact:
|
|
|
|
nameserverentries: |-
|
|
|
|
{{ ( nameservers|d([]) + cloud_resolver|d([]) + configured_nameservers|d([])) | unique | join(',') }}
|
|
|
|
supersede_nameserver:
|
|
|
|
supersede domain-name-servers {{ ( nameservers|d([]) + cloud_resolver|d([])) | unique | join(', ') }};
|
|
|
|
when: dns_early and not dns_late
|
2018-08-23 14:51:52 +00:00
|
|
|
|
|
|
|
- name: gather os specific variables
|
|
|
|
include_vars: "{{ item }}"
|
|
|
|
with_first_found:
|
|
|
|
- files:
|
|
|
|
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
|
|
|
|
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_release }}.yml"
|
|
|
|
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
|
|
|
|
- "{{ ansible_distribution|lower }}.yml"
|
|
|
|
- "{{ ansible_os_family|lower }}.yml"
|
|
|
|
- defaults.yml
|
|
|
|
paths:
|
|
|
|
- ../vars
|
|
|
|
skip: true
|
2018-10-16 14:15:05 +00:00
|
|
|
|
2019-06-20 18:12:51 +00:00
|
|
|
- name: set etcd vars if using kubeadm mode
|
|
|
|
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-22 16:53:16 +00:00
|
|
|
- etcd_deployment_type == "kubeadm"
|
2019-07-30 19:00:10 +00:00
|
|
|
|
|
|
|
- name: check /usr readonly
|
|
|
|
stat:
|
|
|
|
path: "/usr"
|
2021-02-10 13:36:59 +00:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2019-07-30 19:00:10 +00:00
|
|
|
register: usr
|
|
|
|
|
|
|
|
- name: set alternate flexvolume path
|
|
|
|
set_fact:
|
|
|
|
kubelet_flexvolumes_plugins_dir: /var/lib/kubelet/volumeplugins
|
|
|
|
when: not usr.stat.writeable
|
2020-11-02 17:58:06 +00:00
|
|
|
|
2021-04-12 08:05:59 +00:00
|
|
|
- block:
|
|
|
|
- name: Ensure IPv6DualStack featureGate is set when enable_dual_stack_networks is true
|
|
|
|
set_fact:
|
|
|
|
kube_feature_gates: "{{ kube_feature_gates + [ 'IPv6DualStack=true' ] }}"
|
|
|
|
when:
|
|
|
|
- not 'IPv6DualStack=true' in kube_feature_gates
|
|
|
|
|
|
|
|
- name: Ensure IPv6DualStack kubeadm featureGate is set when enable_dual_stack_networks is true
|
|
|
|
set_fact:
|
|
|
|
kubeadm_feature_gates: "{{ kubeadm_feature_gates + [ 'IPv6DualStack=true' ] }}"
|
|
|
|
when:
|
|
|
|
- not 'IPv6DualStack=true' in kubeadm_feature_gates
|
2020-11-02 17:58:06 +00:00
|
|
|
when:
|
|
|
|
- enable_dual_stack_networks
|
2022-06-06 15:00:27 +00:00
|
|
|
- kube_version is version('v1.24.0', '<')
|