d5b21b34c2
* Add an option to deploy K8s app to test e2e network connectivity and cluster DNS resolve via Kubedns for nethost/simple pods (defaults to false). * Parametrize existing k8s apps templates with kube_namespace and kube_config_dir instead of hardcode. * For CoreOS, ensure nameservers from inventory to be put in the first place to allow hostnet pods connectivity via short names or FQDN and hostnet agents to pass as well, if netchecker deployed. Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
139 lines
3.8 KiB
YAML
139 lines
3.8 KiB
YAML
---
|
|
- name: check resolvconf
|
|
shell: which resolvconf
|
|
register: resolvconf
|
|
ignore_errors: yes
|
|
changed_when: false
|
|
|
|
- name: target resolv.conf file
|
|
set_fact:
|
|
resolvconffile: >-
|
|
{%- if resolvconf.rc == 0 -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%}
|
|
when: ansible_os_family != "CoreOS"
|
|
|
|
- name: target temporary resolvconf cloud init file
|
|
set_fact:
|
|
resolvconffile: /tmp/resolveconf_cloud_init_conf
|
|
when: ansible_os_family == "CoreOS"
|
|
|
|
- name: create temporary resolveconf cloud init file
|
|
command: cp -f /etc/resolv.conf "{{ resolvconffile }}"
|
|
when: ansible_os_family == "CoreOS"
|
|
|
|
- name: generate search domains to resolvconf
|
|
set_fact:
|
|
searchentries:
|
|
"{{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join(' ') }}"
|
|
|
|
- name: pick dnsmasq cluster IP
|
|
set_fact:
|
|
dnsmasq_server: >-
|
|
{%- if skip_dnsmasq|bool -%}{{ [ skydns_server ] + upstream_dns_servers|default([]) }}{%- else -%}{{ [ dns_server ] }}{%- endif -%}
|
|
|
|
- name: generate nameservers to resolvconf
|
|
set_fact:
|
|
nameserverentries:
|
|
"{{ dnsmasq_server|default([]) + nameservers|default([]) }}"
|
|
|
|
- name: Remove search and nameserver options from resolvconf head
|
|
lineinfile:
|
|
dest: /etc/resolvconf/resolv.conf.d/head
|
|
state: absent
|
|
regexp: "^{{ item }}.*$"
|
|
backup: yes
|
|
follow: yes
|
|
with_items:
|
|
- search
|
|
- nameserver
|
|
when: resolvconf.rc == 0
|
|
notify: Dnsmasq | update resolvconf
|
|
|
|
- name: Remove search and nameserver options from resolvconf cloud init temporary file
|
|
lineinfile:
|
|
dest: "{{resolvconffile}}"
|
|
state: absent
|
|
regexp: "^{{ item }}.*$"
|
|
backup: yes
|
|
follow: yes
|
|
with_items:
|
|
- search
|
|
- nameserver
|
|
when: ansible_os_family == "CoreOS"
|
|
notify: Dnsmasq | update resolvconf for CoreOS
|
|
|
|
- name: Add search domains to resolvconf file
|
|
lineinfile:
|
|
line: "search {{searchentries}}"
|
|
dest: "{{resolvconffile}}"
|
|
state: present
|
|
insertbefore: BOF
|
|
backup: yes
|
|
follow: yes
|
|
notify: Dnsmasq | update resolvconf
|
|
|
|
- name: Add nameservers to resolv.conf
|
|
blockinfile:
|
|
dest: "{{resolvconffile}}"
|
|
block: |-
|
|
{% for item in nameserverentries -%}
|
|
nameserver {{ item }}
|
|
{% endfor %}
|
|
state: present
|
|
insertafter: "^search default.svc.*$"
|
|
create: yes
|
|
backup: yes
|
|
follow: yes
|
|
marker: "# Ansible nameservers {mark}"
|
|
notify: Dnsmasq | update resolvconf
|
|
|
|
- name: Add options to resolv.conf
|
|
lineinfile:
|
|
line: options {{ item }}
|
|
dest: "{{resolvconffile}}"
|
|
state: present
|
|
regexp: "^options.*{{ item }}$"
|
|
insertafter: EOF
|
|
backup: yes
|
|
follow: yes
|
|
with_items:
|
|
- ndots:{{ ndots }}
|
|
- timeout:2
|
|
- attempts:2
|
|
notify: Dnsmasq | update resolvconf
|
|
|
|
- name: Remove search and nameserver options from resolvconf base
|
|
lineinfile:
|
|
dest: /etc/resolvconf/resolv.conf.d/base
|
|
state: absent
|
|
regexp: "^{{ item }}.*$"
|
|
backup: yes
|
|
follow: yes
|
|
with_items:
|
|
- search
|
|
- nameserver
|
|
when: resolvconf.rc == 0
|
|
notify: Dnsmasq | update resolvconf
|
|
|
|
- name: disable resolv.conf modification by dhclient
|
|
copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/znodnsupdate mode=0755
|
|
notify: Dnsmasq | restart network
|
|
when: ansible_os_family == "Debian"
|
|
|
|
- name: disable resolv.conf modification by dhclient
|
|
copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/nodnsupdate mode=u+x
|
|
notify: Dnsmasq | restart network
|
|
when: ansible_os_family == "RedHat"
|
|
|
|
- name: get temporary resolveconf cloud init file content
|
|
command: cat {{ resolvconffile }}
|
|
register: cloud_config
|
|
when: ansible_os_family == "CoreOS"
|
|
|
|
- name: persist resolvconf cloud init file
|
|
template:
|
|
dest: "{{resolveconf_cloud_init_conf}}"
|
|
src: resolvconf.j2
|
|
owner: root
|
|
mode: 0644
|
|
notify: Dnsmasq | update resolvconf for CoreOS
|
|
when: ansible_os_family == "CoreOS"
|