You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3 KiB

  1. ---
  2. - name: set dns server for docker
  3. set_fact:
  4. docker_dns_servers: "{{ dns_servers }}"
  5. - name: show docker_dns_servers
  6. debug:
  7. msg: "{{ docker_dns_servers }}"
  8. - name: add upstream dns servers
  9. set_fact:
  10. docker_dns_servers: "{{ docker_dns_servers + upstream_dns_servers|default([]) }}"
  11. when: dns_mode in ['coredns', 'coredns_dual']
  12. - name: add global searchdomains
  13. set_fact:
  14. docker_dns_search_domains: "{{ docker_dns_search_domains + searchdomains|default([]) }}"
  15. - name: check system nameservers
  16. shell: set -o pipefail && grep "^nameserver" /etc/resolv.conf | sed -r 's/^nameserver\s*([^#\s]+)\s*(#.*)?/\1/'
  17. args:
  18. executable: /bin/bash
  19. changed_when: False
  20. register: system_nameservers
  21. check_mode: no
  22. - name: check system search domains
  23. # noqa 306 - if resolf.conf has no search domain, grep will exit 1 which would force us to add failed_when: false
  24. # Therefore -o pipefail is not applicable in this specific instance
  25. shell: grep "^search" /etc/resolv.conf | sed -r 's/^search\s*([^#]+)\s*(#.*)?/\1/'
  26. args:
  27. executable: /bin/bash
  28. changed_when: False
  29. register: system_search_domains
  30. check_mode: no
  31. - name: add system nameservers to docker options
  32. set_fact:
  33. docker_dns_servers: "{{ docker_dns_servers | union(system_nameservers.stdout_lines) | unique }}"
  34. when: system_nameservers.stdout
  35. - name: add system search domains to docker options
  36. set_fact:
  37. docker_dns_search_domains: "{{ docker_dns_search_domains | union(system_search_domains.stdout.split()|default([])) | unique }}"
  38. when: system_search_domains.stdout
  39. - name: check number of nameservers
  40. fail:
  41. 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."
  42. when: docker_dns_servers|length > 3 and docker_dns_servers_strict|bool
  43. - name: rtrim number of nameservers to 3
  44. set_fact:
  45. docker_dns_servers: "{{ docker_dns_servers[0:3] }}"
  46. when: docker_dns_servers|length > 3 and not docker_dns_servers_strict|bool
  47. - name: check number of search domains
  48. fail:
  49. msg: "Too many search domains"
  50. when: docker_dns_search_domains|length > 6
  51. - name: check length of search domains
  52. fail:
  53. msg: "Search domains exceeded limit of 256 characters"
  54. when: docker_dns_search_domains|join(' ')|length > 256