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.

75 lines
2.5 KiB

  1. ---
  2. - name: set dns server for docker
  3. set_fact:
  4. docker_dns_servers: |-
  5. {%- if dns_mode in ['kubedns', 'coredns'] -%}
  6. {{ [ skydns_server ] }}
  7. {%- elif dns_mode == 'coredns_dual' -%}
  8. {{ [ skydns_server ] + [ skydns_server_secondary ] }}
  9. {%- elif dns_mode == 'dnsmasq_kubedns' -%}
  10. {{ [ dnsmasq_dns_server ] }}
  11. {%- elif dns_mode == 'manual' -%}
  12. {{ [ manual_dns_server ] }}
  13. {%- endif -%}
  14. - name: set base docker dns facts
  15. set_fact:
  16. docker_dns_search_domains:
  17. - 'default.svc.{{ dns_domain }}'
  18. - 'svc.{{ dns_domain }}'
  19. docker_dns_options:
  20. - ndots:{{ ndots }}
  21. - timeout:2
  22. - attempts:2
  23. - name: add upstream dns servers (only when dnsmasq is not used)
  24. set_fact:
  25. docker_dns_servers: "{{ docker_dns_servers + upstream_dns_servers|default([]) }}"
  26. when: dns_mode in ['kubedns', 'coredns', 'coreos_dual']
  27. - name: add global searchdomains
  28. set_fact:
  29. docker_dns_search_domains: "{{ docker_dns_search_domains + searchdomains|default([]) }}"
  30. - name: check system nameservers
  31. shell: grep "^nameserver" /etc/resolv.conf | sed 's/^nameserver\s*//'
  32. changed_when: False
  33. register: system_nameservers
  34. check_mode: no
  35. - name: check system search domains
  36. shell: grep "^search" /etc/resolv.conf | sed 's/^search\s*//'
  37. changed_when: False
  38. register: system_search_domains
  39. check_mode: no
  40. - name: add system nameservers to docker options
  41. set_fact:
  42. docker_dns_servers: "{{ docker_dns_servers | union(system_nameservers.stdout_lines) | unique }}"
  43. when: system_nameservers.stdout != ""
  44. - name: add system search domains to docker options
  45. set_fact:
  46. docker_dns_search_domains: "{{ docker_dns_search_domains | union(system_search_domains.stdout.split()|default([])) | unique }}"
  47. when: system_search_domains.stdout != ""
  48. - name: check number of nameservers
  49. fail:
  50. msg: "Too many nameservers. You can relax this check by set docker_dns_servers_strict=no and we will only use the first 3."
  51. when: docker_dns_servers|length > 3 and docker_dns_servers_strict|bool
  52. - name: rtrim number of nameservers to 3
  53. set_fact:
  54. docker_dns_servers: "{{ docker_dns_servers[0:3] }}"
  55. when: docker_dns_servers|length > 3 and not docker_dns_servers_strict|bool
  56. - name: check number of search domains
  57. fail:
  58. msg: "Too many search domains"
  59. when: docker_dns_search_domains|length > 6
  60. - name: check length of search domains
  61. fail:
  62. msg: "Search domains exceeded limit of 256 characters"
  63. when: docker_dns_search_domains|join(' ')|length > 256