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