2016-12-21 16:18:11 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: set dns server for docker
|
|
|
|
set_fact:
|
2019-05-02 21:24:21 +00:00
|
|
|
docker_dns_servers: "{{ dns_servers }}"
|
2018-10-10 02:14:33 +00:00
|
|
|
|
|
|
|
- name: show docker_dns_servers
|
|
|
|
debug:
|
2019-05-02 21:24:21 +00:00
|
|
|
msg: "{{ docker_dns_servers }}"
|
2016-12-21 16:18:11 +00:00
|
|
|
|
2019-04-01 19:32:34 +00:00
|
|
|
- name: add upstream dns servers
|
2016-12-21 16:18:11 +00:00
|
|
|
set_fact:
|
|
|
|
docker_dns_servers: "{{ docker_dns_servers + upstream_dns_servers|default([]) }}"
|
2019-04-01 19:32:34 +00:00
|
|
|
when: dns_mode in ['coredns', 'coredns_dual']
|
2016-12-21 16:18:11 +00:00
|
|
|
|
|
|
|
- name: add global searchdomains
|
|
|
|
set_fact:
|
|
|
|
docker_dns_search_domains: "{{ docker_dns_search_domains + searchdomains|default([]) }}"
|
|
|
|
|
2020-08-28 08:20:53 +00:00
|
|
|
- name: check system nameservers
|
|
|
|
shell: set -o pipefail && grep "^nameserver" /etc/resolv.conf | sed -r 's/^nameserver\s*([^#\s]+)\s*(#.*)?/\1/'
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2016-12-21 16:18:11 +00:00
|
|
|
changed_when: False
|
|
|
|
register: system_nameservers
|
2017-02-06 18:13:21 +00:00
|
|
|
check_mode: no
|
2016-12-21 16:18:11 +00:00
|
|
|
|
2020-08-28 08:20:53 +00:00
|
|
|
- name: check system search domains
|
|
|
|
# noqa 306 - if resolf.conf has no search domain, grep will exit 1 which would force us to add failed_when: false
|
|
|
|
# Therefore -o pipefail is not applicable in this specific instance
|
2019-10-16 11:27:40 +00:00
|
|
|
shell: grep "^search" /etc/resolv.conf | sed -r 's/^search\s*([^#]+)\s*(#.*)?/\1/'
|
2020-08-28 08:20:53 +00:00
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2016-12-21 16:18:11 +00:00
|
|
|
changed_when: False
|
|
|
|
register: system_search_domains
|
2017-02-06 18:13:21 +00:00
|
|
|
check_mode: no
|
2016-12-21 16:18:11 +00:00
|
|
|
|
|
|
|
- name: add system nameservers to docker options
|
|
|
|
set_fact:
|
2017-01-09 12:46:05 +00:00
|
|
|
docker_dns_servers: "{{ docker_dns_servers | union(system_nameservers.stdout_lines) | unique }}"
|
2019-04-29 06:00:20 +00:00
|
|
|
when: system_nameservers.stdout
|
2016-12-21 16:18:11 +00:00
|
|
|
|
|
|
|
- name: add system search domains to docker options
|
|
|
|
set_fact:
|
2017-12-13 07:39:38 +00:00
|
|
|
docker_dns_search_domains: "{{ docker_dns_search_domains | union(system_search_domains.stdout.split()|default([])) | unique }}"
|
2019-04-29 06:00:20 +00:00
|
|
|
when: system_search_domains.stdout
|
2016-12-21 16:18:11 +00:00
|
|
|
|
|
|
|
- name: check number of nameservers
|
2017-02-17 21:22:34 +00:00
|
|
|
fail:
|
2018-06-05 08:45:02 +00:00
|
|
|
msg: "Too many nameservers. You can relax this check by set docker_dns_servers_strict=false in all.yml and we will only use the first 3."
|
2017-06-26 09:29:12 +00:00
|
|
|
when: docker_dns_servers|length > 3 and docker_dns_servers_strict|bool
|
|
|
|
|
|
|
|
- name: rtrim number of nameservers to 3
|
|
|
|
set_fact:
|
|
|
|
docker_dns_servers: "{{ docker_dns_servers[0:3] }}"
|
|
|
|
when: docker_dns_servers|length > 3 and not docker_dns_servers_strict|bool
|
2016-12-21 16:18:11 +00:00
|
|
|
|
|
|
|
- name: check number of search domains
|
2017-02-17 21:22:34 +00:00
|
|
|
fail:
|
|
|
|
msg: "Too many search domains"
|
2016-12-21 16:18:11 +00:00
|
|
|
when: docker_dns_search_domains|length > 6
|
|
|
|
|
|
|
|
- name: check length of search domains
|
2017-02-17 21:22:34 +00:00
|
|
|
fail:
|
|
|
|
msg: "Search domains exceeded limit of 256 characters"
|
2016-12-21 16:18:11 +00:00
|
|
|
when: docker_dns_search_domains|join(' ')|length > 256
|