2016-09-22 17:14:51 +00:00
|
|
|
---
|
|
|
|
- name: check resolvconf
|
|
|
|
shell: which resolvconf
|
|
|
|
register: resolvconf
|
|
|
|
ignore_errors: yes
|
2016-10-18 10:28:28 +00:00
|
|
|
changed_when: false
|
2016-12-07 15:57:05 +00:00
|
|
|
tags: facts
|
|
|
|
|
|
|
|
- name: check kubelet
|
|
|
|
stat:
|
|
|
|
path: "{{ bin_dir }}/kubelet"
|
|
|
|
register: kubelet
|
|
|
|
changed_when: false
|
|
|
|
tags: facts
|
|
|
|
|
|
|
|
- name: check if early DNS configuration stage
|
|
|
|
set_fact:
|
|
|
|
dns_early: >-
|
|
|
|
{%- if kubelet.stat.exists -%}false{%- else -%}true{%- endif -%}
|
|
|
|
tags: facts
|
2016-09-22 17:14:51 +00:00
|
|
|
|
|
|
|
- name: target resolv.conf file
|
|
|
|
set_fact:
|
|
|
|
resolvconffile: >-
|
|
|
|
{%- if resolvconf.rc == 0 -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%}
|
2016-11-23 14:49:10 +00:00
|
|
|
when: ansible_os_family != "CoreOS"
|
2016-12-07 15:57:05 +00:00
|
|
|
tags: facts
|
2016-11-23 14:49:10 +00:00
|
|
|
|
|
|
|
- name: target temporary resolvconf cloud init file
|
|
|
|
set_fact:
|
|
|
|
resolvconffile: /tmp/resolveconf_cloud_init_conf
|
|
|
|
when: ansible_os_family == "CoreOS"
|
2016-12-07 15:57:05 +00:00
|
|
|
tags: facts
|
2016-11-23 14:49:10 +00:00
|
|
|
|
|
|
|
- name: create temporary resolveconf cloud init file
|
|
|
|
command: cp -f /etc/resolv.conf "{{ resolvconffile }}"
|
|
|
|
when: ansible_os_family == "CoreOS"
|
2016-09-22 17:14:51 +00:00
|
|
|
|
|
|
|
- name: generate search domains to resolvconf
|
|
|
|
set_fact:
|
|
|
|
searchentries:
|
|
|
|
"{{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join(' ') }}"
|
2016-12-07 15:57:05 +00:00
|
|
|
tags: facts
|
|
|
|
|
|
|
|
- name: decide on dns server IP
|
|
|
|
set_fact:
|
|
|
|
dns_server_real: >-
|
|
|
|
{%- if dns_early|bool -%}{{default_resolver}}{%- else -%}{{dns_server}}{%- endif -%}
|
2016-09-22 17:14:51 +00:00
|
|
|
|
2016-12-07 15:57:05 +00:00
|
|
|
- name: pick dnsmasq cluster IP or default resolver
|
2016-09-22 17:14:51 +00:00
|
|
|
set_fact:
|
2016-12-07 15:57:05 +00:00
|
|
|
dnsmasq_server: |-
|
|
|
|
{%- if skip_dnsmasq|bool and not dns_early|bool -%}
|
|
|
|
{{ [ skydns_server ] + upstream_dns_servers|default([]) }}
|
|
|
|
{%- elif dns_early|bool -%}
|
|
|
|
{{ [ dns_server_real ] + upstream_dns_servers|default([]) }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ [ dns_server ] }}
|
|
|
|
{%- endif -%}
|
|
|
|
tags: facts
|
2016-09-22 17:14:51 +00:00
|
|
|
|
|
|
|
- name: generate nameservers to resolvconf
|
|
|
|
set_fact:
|
|
|
|
nameserverentries:
|
2016-09-22 17:14:51 +00:00
|
|
|
"{{ dnsmasq_server|default([]) + nameservers|default([]) }}"
|
2016-12-07 15:57:05 +00:00
|
|
|
tags: facts
|
2016-09-22 17:14:51 +00:00
|
|
|
|
|
|
|
- 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
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | update resolvconf
|
2016-09-22 17:14:51 +00:00
|
|
|
|
2016-09-30 15:23:47 +00:00
|
|
|
- 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"
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | update resolvconf for CoreOS
|
2016-09-30 15:23:47 +00:00
|
|
|
|
|
|
|
- name: Add search domains to resolvconf file
|
2016-09-22 17:14:51 +00:00
|
|
|
lineinfile:
|
|
|
|
line: "search {{searchentries}}"
|
|
|
|
dest: "{{resolvconffile}}"
|
|
|
|
state: present
|
|
|
|
insertbefore: BOF
|
|
|
|
backup: yes
|
|
|
|
follow: yes
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | update resolvconf
|
2016-09-22 17:14:51 +00:00
|
|
|
|
2016-09-22 17:14:51 +00:00
|
|
|
- name: Add nameservers to resolv.conf
|
2016-09-22 17:14:51 +00:00
|
|
|
blockinfile:
|
|
|
|
dest: "{{resolvconffile}}"
|
|
|
|
block: |-
|
|
|
|
{% for item in nameserverentries -%}
|
|
|
|
nameserver {{ item }}
|
|
|
|
{% endfor %}
|
|
|
|
state: present
|
2016-09-30 15:23:47 +00:00
|
|
|
insertafter: "^search default.svc.*$"
|
2016-09-22 17:14:51 +00:00
|
|
|
create: yes
|
|
|
|
backup: yes
|
|
|
|
follow: yes
|
|
|
|
marker: "# Ansible nameservers {mark}"
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | update resolvconf
|
2016-09-22 17:14:51 +00:00
|
|
|
|
|
|
|
- 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:
|
2016-09-27 09:54:12 +00:00
|
|
|
- ndots:{{ ndots }}
|
2016-09-22 17:14:51 +00:00
|
|
|
- timeout:2
|
|
|
|
- attempts:2
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | update resolvconf
|
2016-09-22 17:14:51 +00:00
|
|
|
|
|
|
|
- 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
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | update resolvconf
|
2016-09-22 17:14:51 +00:00
|
|
|
|
|
|
|
- name: disable resolv.conf modification by dhclient
|
|
|
|
copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/znodnsupdate mode=0755
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | restart network
|
2016-09-22 17:14:51 +00:00
|
|
|
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
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | restart network
|
2016-09-22 17:14:51 +00:00
|
|
|
when: ansible_os_family == "RedHat"
|
2016-11-23 14:49:10 +00:00
|
|
|
|
|
|
|
- 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
|
2016-12-07 15:57:05 +00:00
|
|
|
notify: Preinstall | update resolvconf for CoreOS
|
2016-11-23 14:49:10 +00:00
|
|
|
when: ansible_os_family == "CoreOS"
|