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.

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