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.

73 lines
2.4 KiB

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