2016-12-22 00:18:11 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: set dns server for docker
|
|
|
|
set_fact:
|
|
|
|
docker_dns_servers: |-
|
|
|
|
{%- if dns_mode == 'kubedns' -%}
|
|
|
|
{{ [ skydns_server ] }}
|
|
|
|
{%- elif dns_mode == 'dnsmasq_kubedns' -%}
|
|
|
|
{{ [ dns_server ] }}
|
|
|
|
{%- endif -%}
|
|
|
|
|
|
|
|
- name: set base docker dns facts
|
|
|
|
set_fact:
|
|
|
|
docker_dns_search_domains:
|
|
|
|
- 'default.svc.{{ dns_domain }}'
|
|
|
|
- 'svc.{{ dns_domain }}'
|
|
|
|
docker_dns_options:
|
|
|
|
- ndots:{{ ndots }}
|
|
|
|
- timeout:2
|
|
|
|
- attempts:2
|
|
|
|
|
|
|
|
- name: add upstream dns servers (only when dnsmasq is not used)
|
|
|
|
set_fact:
|
|
|
|
docker_dns_servers: "{{ docker_dns_servers + upstream_dns_servers|default([]) }}"
|
|
|
|
when: dns_mode == 'kubedns'
|
|
|
|
|
|
|
|
- name: add global searchdomains
|
|
|
|
set_fact:
|
|
|
|
docker_dns_search_domains: "{{ docker_dns_search_domains + searchdomains|default([]) }}"
|
|
|
|
|
|
|
|
- name: check system nameservers
|
|
|
|
shell: grep "^nameserver" /etc/resolv.conf | sed 's/^nameserver\s*//'
|
|
|
|
changed_when: False
|
|
|
|
register: system_nameservers
|
2017-02-07 02:13:21 +08:00
|
|
|
check_mode: no
|
2016-12-22 00:18:11 +08:00
|
|
|
|
|
|
|
- name: check system search domains
|
|
|
|
shell: grep "^search" /etc/resolv.conf | sed 's/^search\s*//'
|
|
|
|
changed_when: False
|
|
|
|
register: system_search_domains
|
2017-02-07 02:13:21 +08:00
|
|
|
check_mode: no
|
2016-12-22 00:18:11 +08:00
|
|
|
|
|
|
|
- name: add system nameservers to docker options
|
|
|
|
set_fact:
|
2017-01-09 20:46:05 +08:00
|
|
|
docker_dns_servers: "{{ docker_dns_servers | union(system_nameservers.stdout_lines) | unique }}"
|
|
|
|
when: system_nameservers.stdout != ""
|
2016-12-22 00:18:11 +08:00
|
|
|
|
|
|
|
- name: add system search domains to docker options
|
|
|
|
set_fact:
|
2017-01-09 20:46:05 +08:00
|
|
|
docker_dns_search_domains: "{{ docker_dns_search_domains | union(system_search_domains.stdout.split(' ')|default([])) | unique }}"
|
|
|
|
when: system_search_domains.stdout != ""
|
2016-12-22 00:18:11 +08:00
|
|
|
|
|
|
|
- name: check number of nameservers
|
2017-02-18 05:22:34 +08:00
|
|
|
fail:
|
|
|
|
msg: "Too many nameservers"
|
2016-12-22 00:18:11 +08:00
|
|
|
when: docker_dns_servers|length > 3
|
|
|
|
|
|
|
|
- name: check number of search domains
|
2017-02-18 05:22:34 +08:00
|
|
|
fail:
|
|
|
|
msg: "Too many search domains"
|
2016-12-22 00:18:11 +08:00
|
|
|
when: docker_dns_search_domains|length > 6
|
|
|
|
|
|
|
|
- name: check length of search domains
|
2017-02-18 05:22:34 +08:00
|
|
|
fail:
|
|
|
|
msg: "Search domains exceeded limit of 256 characters"
|
2016-12-22 00:18:11 +08:00
|
|
|
when: docker_dns_search_domains|join(' ')|length > 256
|