Files
kubespray/roles/kubernetes/preinstall/tasks/0060-resolvconf.yml
k8s-infra-cherrypick-robotandShuu 25be587fdd fix: skip None resolvconf paths on Ansible Core 2.19 (#13557)
Empty base/head facts render to None on Ansible Core 2.19, which
difference(['']) does not remove. Use select to drop both.

Co-authored-by: Shuu <shuu.n@protonmail.com>
2026-09-24 06:54:19 +00:00

58 lines
2.1 KiB
YAML

---
- name: Create temporary resolveconf cloud init file
command: cp -f /etc/resolv.conf "{{ resolvconffile }}"
when: ansible_facts['os_family'] == "Flatcar"
- name: Add domain/search/nameservers/options to resolv.conf
blockinfile:
path: "{{ resolvconffile }}"
block: |-
domain {{ dns_domain }}
search {{ (default_searchdomains + searchdomains) | join(' ') }}
{% for item in nameserverentries %}
nameserver {{ item }}
{% endfor %}
options ndots:{{ ndots }} timeout:{{ dns_timeout }} attempts:{{ dns_attempts }}
state: present
insertbefore: BOF
create: true
backup: "{{ not resolvconf_stat.stat.islnk }}"
marker: "# Ansible entries {mark}"
mode: "0644"
notify: Preinstall | propagate resolvconf to k8s components
- name: Remove search/domain/nameserver options before block
replace:
path: "{{ item[0] }}"
regexp: '^{{ item[1] }}[^#]*(?=# Ansible entries BEGIN)'
backup: "{{ not resolvconf_stat.stat.islnk }}"
with_nested:
- "{{ [resolvconffile, base | default(''), head | default('')] | select | list }}"
- [ 'search\s', 'nameserver\s', 'domain\s', 'options\s' ]
notify: Preinstall | propagate resolvconf to k8s components
- name: Remove search/domain/nameserver options after block
replace:
path: "{{ item[0] }}"
regexp: '(# Ansible entries END\n(?:(?!^{{ item[1] }}).*\n)*)(?:^{{ item[1] }}.*\n?)+'
replace: '\1'
backup: "{{ not resolvconf_stat.stat.islnk }}"
with_nested:
- "{{ [resolvconffile, base | default(''), head | default('')] | select | list }}"
- [ 'search\s', 'nameserver\s', 'domain\s', 'options\s' ]
notify: Preinstall | propagate resolvconf to k8s components
- name: Get temporary resolveconf cloud init file content
command: cat {{ resolvconffile }}
register: cloud_config
when: ansible_facts['os_family'] == "Flatcar"
- name: Persist resolvconf cloud init file
template:
dest: "{{ resolveconf_cloud_init_conf }}"
src: resolvconf.j2
owner: root
mode: "0644"
notify: Preinstall | propagate resolvconf to k8s components
when: ansible_facts['os_family'] == "Flatcar"